Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context Manager? #50

Open
Beefster09 opened this issue Jun 4, 2018 · 2 comments
Open

Context Manager? #50

Beefster09 opened this issue Jun 4, 2018 · 2 comments

Comments

@Beefster09
Copy link

I find it a bit wonky that closing the watch can only be done through the destructor. Maybe it isn't the end of the world, but this sorta locks it to cPython.

@dsoprea
Copy link
Owner

dsoprea commented Jul 7, 2018

Please clarify or provide a supporting link.

@Beefster09
Copy link
Author

Most things of this nature do their resource management through __enter__ and __exit__ (so that it works with with) rather than relying on refcounting and the immediate object destruction and __del__ call. Since only cPython has the immediate destruction behavior, this would cause severe resource leaks on other implementations of Python that do not use refcounting for object lifetime.

Even on cPython, you can create a resource leak by keeping a reference to the watch in an object cycle, making it only get closed if and when the garbage collector runs.

It's true that this isn't really an issue for most use cases, but it's not particularly responsible IMO to depend on destructors for resource cleanup. That's a C++ thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants