Re: Block-structured resource handling via decorators

2005-07-30 Thread John Perks and Sarah Mount
> The only cases I see the first school of thought is when the resource > in question is "scarce" in some way. By "resource" I meant anything with some sort of acquire/release semantics. There may be plenty of threading.Locks available, but it's still important that a given Lock is released when n

Re: Block-structured resource handling via decorators

2005-07-30 Thread Michele Simionato
I will shamelessly point out my decorator module: http://www.phyast.pitt.edu/~micheles/python/decorator.zip The documentation is here: http://www.phyast.pitt.edu/~micheles/python/documentation.htm There is an example of redirecting stdout which is relevant to this thread. HTH, Michele

Re: Block-structured resource handling via decorators

2005-07-29 Thread Paul Rubin
Mike Meyer <[EMAIL PROTECTED]> writes: > > When handling resources in Python, where the scope of the resource is > > known, there seem to be two schools of thought: > > (1) Explicit: ... > > (2) Implicit: let the GC handle it. > > The only cases I see the first school of thought is when the resour

Re: Block-structured resource handling via decorators

2005-07-29 Thread Mike Meyer
"John Perks and Sarah Mount" <[EMAIL PROTECTED]> writes: > When handling resources in Python, where the scope of the resource is > known, there seem to be two schools of thought: > > (1) Explicit: > f = open(fname) > try: > # ... > finally: > f.close() > > (2) Implicit: let the GC handle i

Re: Block-structured resource handling via decorators

2005-07-29 Thread Neil Hodgson
John Perks: > When handling resources in Python, where the scope of the resource is > known, there seem to be two schools of thought: > ... This is part of what PEP 343 addresses: http://www.python.org/peps/pep-0343.html Neil -- http://mail.python.org/mailman/listinfo/python-list

Block-structured resource handling via decorators

2005-07-29 Thread John Perks and Sarah Mount
When handling resources in Python, where the scope of the resource is known, there seem to be two schools of thought: (1) Explicit: f = open(fname) try: # ... finally: f.close() (2) Implicit: let the GC handle it. I've come up with a third method that uses decorators to achieve a useful