Thread safety of the python API
aahz at pythoncraft.com
Fri Mar 14 19:46:58 CET 2003
In article <412a1fa3.0303141010.588088e3 at posting.google.com>,
Stephen Ludin <sludin at ludin.org> 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 pythoncraft.com) <*> http://www.pythoncraft.com/
Register for PyCon now! http://www.python.org/pycon/reg.html
More information about the Python-list