How can you ensure registered atexit function will run with AppHelper.runEventLoop() in PyObjC?

StackOverflow https://stackoverflow.com/questions/1255025

  •  12-09-2019
  •  | 
  •  

Question

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...

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top