Thread safety of the python API

Aahz aahz at
Fri Mar 14 19:46:58 CET 2003

In article <412a1fa3.0303141010.588088e3 at>,
Stephen Ludin <sludin at> wrote:
>From what I am hearing, this is 'bad' and is not a valid use scenario
>for the API.  It is not safe to have two threads simultaneously using
>the Python API.  In order to make it safe, I need to get the GIL (or
>some other global mutex) before I call PyInt_FromLong, and then
>release it.  Is this correct?

Correct, you need to acquire the GIL before using *any* Python API call.
That's because Python uses several global internal data structures to
manage objects obtained through the API (e.g. garbage collection).
Aahz (aahz at           <*>

Register for PyCon now!

More information about the Python-list mailing list