This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author fdirosa
Recipients Rhamphoryncus, fdirosa, grahamd, nnorwitz, timbishop, vslavik
Date 2008-07-24.12:30:45
SpamBayes Score 0.0022271138
Marked as misclassified No
Message-id <1216902649.89.0.610240495349.issue1758146@psf.upfronthosting.co.za>
In-reply-to
Content
I'm unsure if you are understanding what I'm doing so here is the 
story...

I stepped through Py_Initialize and this function takes the main 
interpreter and it's initial thread state and makes that the GIL thread 
state.

The following code in Py_Initialize hijacks the main interpreter and 
thread state for GIL use...

/* auto-thread-state API, if available */
#ifdef WITH_THREAD
    _PyGILState_Init(interp, tstate);
#endif /* WITH_THREAD */

WITH_THREAD is defined since I'm using multithreading in my application.

So now if you create thread states from the main interpeter and use the 
PyEval_Acquire/Release and PyThreadState_Swap you will get the 
assertion when compiled with the DEBUG option. If you use the 
PyGILState_Ensure and PyGILState_Release functions you don't. 

What I'm doing is that I have a Windows application with embedded 
python.  The application spawns multiple threads each running a python 
script.  Each application thread has its own unique PyThreadState 
created from the main interpreter because I wanted all the modules 
loaded only once for resource conservation purposes (thus use only one 
interpreter). I used PyEval_Acquire/Release and PyThreadState_Swap to 
handle swapping in each application thread's thread state when each one 
uses the python API.  This worked great in RELEASE compilation but in 
DEBUG it asserted.  Now that I use the GIL functions it works well and 
not only that, I removed the code I had put in myself to handle python 
callback's into the application and avoiding deadlocks by calling 
PyEval_Acquire onto itself (since it uses mutexes which doesn't do 
reference counting so it could deadlock waiting on itself to complete)
History
Date User Action Args
2008-07-24 12:30:50fdirosasetspambayes_score: 0.00222711 -> 0.0022271138
recipients: + fdirosa, nnorwitz, Rhamphoryncus, timbishop, vslavik, grahamd
2008-07-24 12:30:50fdirosasetspambayes_score: 0.00222711 -> 0.00222711
messageid: <1216902649.89.0.610240495349.issue1758146@psf.upfronthosting.co.za>
2008-07-24 12:30:48fdirosalinkissue1758146 messages
2008-07-24 12:30:46fdirosacreate