Re: no cleanup on TERM signal

2008-05-02 Thread Laszlo Nagy
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

Re: no cleanup on TERM signal

2008-05-02 Thread Duncan Booth
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

Re: no cleanup on TERM signal

2008-05-02 Thread Christian Heimes
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: >

Re: no cleanup on TERM signal

2008-05-02 Thread Laszlo Nagy
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

Re: no cleanup on TERM signal

2008-05-01 Thread Marc 'BlackJack' Rintsch
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

no cleanup on TERM signal

2008-05-01 Thread Yves Dorfsman
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