Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
Block-structured resource handling via decorators
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Mike Meyer, post: 1830891"] The only cases I see the first school of thought is when the resource in question is "scarce" in some way. For example, most OS's place a limit on the number of open files a process can have, some rather tight. CPython's garbage collector will close an open file when it leaves scope. Jython's GC will close it when the file is collected, but you have no idea of when that will be, and an "open" failing won't trigger a GC. So in this case, the first form is less likely to fail unexpectedly. Well, I'd say that using a string for cleanup and a function for init is unpythonic. But the general idea seems to be a good one. Making it easy to deal with resources that must be explicitly released is a good thing. The question is whether having to turn your scope into a function to do this is more trouble than it's worth. I'd certainly be interested in seeing the implementation. <mike [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
Block-structured resource handling via decorators
Top