views:

122

answers:

1

Hi all,

I'm just wondering why I my registered an atexit function... e.g.

import atexit
atexit.register(somefunc)
...
AppHelper.runEventLoop()

Of course I know when will atexit won't work. When I comment out AppHelper.runEventLoop() the atexit function gets called. I also browsed my pyobjc egg, and I saw under __init__.py under objc package the following code:

import atexit
atexit.register(recycleAutoreleasePool)

I looked for any reference within the egg to no avail. I also tried surrounding a try-finally shell around AppHelper.runEventLoop(), and the commands in the finally block won't get called.

Hope someone could help me out here.

P.S. Assuming I don't want to use Application delegate's applicationShouldTerminate: method...

+1  A: 

I believe you do need delegates, because otherwise the event loop can exit the process rather abruptly (kind of like os._exit) and therefore not give the Python runtime a chance to run termination code such as finally clauses, atexit functions, etc etc.

Alex Martelli