PyEval_CallObject and threads

Tim Peters tim.one at home.com
Mon Mar 12 14:45:43 EST 2001


[Phlip]
> My colleague came over and asked me to write this:
>
> "We got multiple C++ pthreads calling PyEval_CallObject. How threadsafe
> is the Python API? A C++ module using Boost BPL creates multiple threads,
> which then call back into Python. When two threads simultaneously call
> PyEval_CallObject we go boom."
>
> I will now go examine his serialization primitives. But if anyone has any
> better ideas...

With very few exceptions, all calls to Python C API functions must be made
while holding the global interpreter lock.  The exceptions have mostly to do
with a handful of functions related to initialization and shutdown.  See the
section "Thread State and the Global Interpreter Lock" in the Python/C API
Reference Manual for details.





More information about the Python-list mailing list