[Pyobjc-dev] Not calling 'finally'
Brought to you by:
ronaldoussoren
From: Bob S. <rsw...@tr...> - 2003-06-26 14:33:54
|
We have a Cocoa-based product using PyObjC that starts up some background processes. When the application quits, we want to stop them. As long as there are no errors, everything works fine - we create the processes in applicationDidFinishLaunching_ and kill them in applicationWillTerminate_ However, I noticed while debugging that if I got a python error that stopped the main process that the daemons would keep on running. applicationWillTerminate_ must not have been called. So, I decided to add a try/finally block in the main code: if __name__ == '__main__: try: AppHelper.runEventLoop() finally: MyController.stopDaemons() where MyController.stopDaemons() is a staticmethod that stops the background processes. However, I put print statements into stopDaemons and find that while it is called properly in applicationWillTerminate_, it does not seem to be called in the finally block when I quit the application. It is possible that quitting calls os._exit which according to Python in a Nutshell (p 274) does not invoke clean-up handlers. I'm not sure if this is the case, or if print cannot be called when the application is terminating. Is such a try/finally construct useful here? How do I ensure proper cleanup even on abnormal termination? Thanks for your help, Bob Swerdlow COO Transpose rsw...@tr... 207-781-8284 http://www.transpose.com ---------------------------------- Fight Spam! Add this link to your signature (as I did): http://wecanstopspam.org Click through to find out more. ---------------------------------- |