You can replace the try/finally code with a "with resource:
do_something()" block if the object supporst the context manager protocol.
I'm using 2.4 so...
If you want to run some code during the shutdown phase of the Python
process you can register a callback function in the "atexit" module
Christian Heimes <[EMAIL PROTECTED]> wrote:
>> res = create_resource()
>> try:
>>use_resource()
>> finally:
>>res.close() # Must free resource, but the object can still be
>>alive...
>
> You can replace the try/finally code with a "with resource:
> do_something()" block if the object
Laszlo Nagy schrieb:
> For sensitive resources, instead of writing __del__ methods, you should
> create a "close()" method. Python does this with file objects, DB API
> 2.0 with database connection objects etc. Then you can do
>
> res = create_resource()
> try:
>use_resource()
> finally:
>
Yves Dorfsman wrote:
I did a few tests with this script:
class byebye:
def __del__(self):
print 'Bye, bye...'
x = byebye()
x.del() gets executed if:
-I del x, then run gc.collect()
-simply exit the script
-get the script to abort on an exception
But if I kill it with the default sign
On Fri, 02 May 2008 04:36:06 +, Yves Dorfsman wrote:
> x.del() gets executed if:
> -I del x, then run gc.collect()
> -simply exit the script
> -get the script to abort on an exception
>
> But if I kill it with the default signal TERM, the script dies, but I don't
> get the message, so I am a
I did a few tests with this script:
class byebye:
def __del__(self):
print 'Bye, bye...'
x = byebye()
x.del() gets executed if:
-I del x, then run gc.collect()
-simply exit the script
-get the script to abort on an exception
But if I kill it with the default signal TERM, the script di