3 ms·
The "With" style construct is the correct way to handle this. Embedding resources like file-descriptors in objects is a Bad Idea. Python has added the "with"
by aidenn0 16y ago
The "With" style construct is the correct way to handle this. Embedding resources like file-descriptors in objects is a Bad Idea.
Python has added the "with" construct so it can move away from ref-counted implementations, because the amortized time for refcounting is slower, and even if you don't care about that, there is still the circular reference problem.
[edit]
I should make it clear I think tying an FDs lifetime to that of an object is a Bad Idea; I'm not suggesting a blanket ban on ever having a FD stored in an object.