[Pyobjc-dev] Program shutdown order issue
Brought to you by:
ronaldoussoren
From: Ronald O. <ron...@ma...> - 2015-07-22 01:16:18
|
Hi, In issue #124 <https://bitbucket.org/ronaldoussoren/pyobjc/issues/124/odd-crash-when-deallocating-oc_pythonarray <https://bitbucket.org/ronaldoussoren/pyobjc/issues/124/odd-crash-when-deallocating-oc_pythonarray>> it appears that there is a race condition when cleanly existing an application. The application launching stub basically does: Py_Initialize(); PyRun_….(); /* Actually run the main python script which starts a (Cocoa) eventloop */ Py_Finalize(); The race condition occurs during (or after) the last line: some background process of the Cocoa frameworks still has a reference to a Python object and tries to use it. When you’re unlucky this happens when the interpreter is already marked as unitialized and you get a crash when PyObjC tries to call into the interpreter. Does anyone know of a way to run code *after* Cocoa’s house keeping code is idle? The alternative would be to not call Py_Finalize(), but then the interpreter doesn’t shut down cleanly and that can have unwanted side effects as well (such as files not being closed cleanly, which might leave buffers unflushed). Ronald |