-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Odd crash when deallocating OC_PythonArray #124
Comments
Original comment by Kentzo (Bitbucket: Kentzo, GitHub: Kentzo). I updated the code to the following:
But it still crashes, with slightly different exception:
I'm going to try to use NSString instead of OC_PythonUnicode. |
Original comment by Kentzo (Bitbucket: Kentzo, GitHub: Kentzo). The final versions seems to work, but since bug is occasional it's hard to be sure:
|
Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren). Not sure what's going on here. The first crash log seems to indicate that this happens during/after interpreter shutdown (see PyEval_RestoreThread in Python/ceval.c). What I think happens is that the .app calls Py_Finalize and after that either the main thread or some other thread cleans up Cocoa and that calls back into Python again. That fails because the Python interpreter is already gone. BTW. Which version of PyObjC do you use? And how do you build the application bundle? Using py2app or something else? I have to think about this a bit more, but think I'll work around this in py2app by not calling Py_Finalize. That's not ideal (because the usual orderly shutdown for Python objects is not run), but better than the alternative. |
Original comment by Kentzo (Bitbucket: Kentzo, GitHub: Kentzo). I'm using pyobjc-core 3.0.4, bundle is created by using pyqtdeploy. The code responsible for starting (and finishing) python interpreter can be found here: https://github.com/GreatFruitOmsk/pyqtdeploy/blob/master/pyqtdeploy/builder/lib/pyqtdeploy_start.cpp |
Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren). Pyqtdeploy does the same as py2app: it calls py_finalize at the end, and the orderly shutdown of cocoa can happen after that call. I'm not sure if there is a way to avoid crashes here. For Python 3 it might be possible to invalidate all proxy objects, but that will likely have other unwanted side effects (such as silently erasing a user setting instead of crashing). -- |
Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren). I think I can fix this particular crash on the PyObjC side by adding more code to -[OC_Python* release] and dealloc, those basically need to check if the interpreter is initialised before calling into Python. That will have a small performance impact, but that cannot be helped. I don't know yet how to fix this in general though. There is a race condition between shutdown of Python and cleanup of Cocoa. I can work around this in the management of reference counts, but not when Cocoa tries to call into Python code that does something more substantial. I have a (partial) workaround in changeset 68804363ebf4 (not yet pushed to the repository) |
Original comment by Kentzo (Bitbucket: Kentzo, GitHub: Kentzo). @ronaldoussoren Maybe Python should finalize after Cocoa's run loop dies? |
Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren). It already does, but not before all other threads have died. What seems to happen in the first crash dump is that Py_Finalize is working on cleaning up the interpreter (and has already marked it as being no longer valid), while another thread (Thread 2) is still doing some work with a OC_PythonArray object (reducing the refcount). The only way you can be sure to not have crashes in this case is to remove the call to Py_Finalize in |
Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren). Workaround for a race condition between interpreter shutdown and Cocoa cleanup when exiting an application. See issue #124 |
Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren). Removing version: 3.0 (automated comment) |
Closing this issue because there is a workaround for this in PyObjC and there's nothing I can do beyond that. |
Original report by Kentzo (Bitbucket: Kentzo, GitHub: Kentzo).
I have an odd crash that only happens occasionally on exit.
Unfortunately I cannot post the code to reproduce it right now, but what I do is basically store a python list in NSUserDefaults by using the setObject_forKey_ method like this:
I only have pyobjc-core installed.
Here is the crash report.
The text was updated successfully, but these errors were encountered: