Program shutdown order issue

Ronald Oussoren <[email protected]> Tue, 21 Jul 2015 18:15:27 +0200
Newsgroups gmane.comp.python.pyobjc.devel
Message-ID <[email protected]>
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

------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/

_______________________________________________
Pyobjc-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyobjc-dev