[Pyrex] Callbacks from other threads (crash in PyGILState_Release)

Jani Hakala jahakala at cc.jyu.fi
Tue Jun 20 22:52:46 UTC 2006


Geoff Schmidt <gschmidt at gschmidt.org> writes:

>
> I tried adding the extra PyEval_Save/RestoreThread that you show in  
> your example, but I still get the same segfault. The revised code is  
> below. Could you take a look and tell me if I understood your advise?
>
I think you need to call PyEval_InitThreads() before pthread_create. 

 void PyEval_InitThreads( )
    "Initialize and acquire the global interpreter lock. It should
     be called in the main thread before creating a second thread or
     engaging in any other thread operations such as
     PyEval_ReleaseLock() or PyEval_ReleaseThread(tstate). It is not
     needed before calling PyEval_SaveThread() or PyEval_RestoreThread()."
 ...
    "When only the main thread exists, no lock operations are
     needed. This is a common situation (most Python programs do not
     use threads), and the lock operations slow the interpreter down
     a bit. Therefore, the lock is not created initially."

Jani Hakala



More information about the Pyrex mailing list