Embedding Python 2.2 in non-reentrant application
Martin v. Loewis
martin at v.loewis.de
Tue Jun 11 16:41:30 EDT 2002
"Stefan Werner" <stefan1werner at hotmail.com> writes:
> I am working on embedding Python 2.2 in a large scale application. Now the
> problem is, that Python 2.2 supports multithreading, where the functions we
> want to expose to Python are not threadsafe. Is there something like a flag
> to make my whole module single-threaded for Python access or do I have to
> wrap every single function call in
> Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS macros?
No, you don't have to do anything. Inside a C function, you hold the
GIL, and any other Python thread will block while your C function is
running. It is precisely that
Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS bracket that allows
thread-safe libraries to give up the GIL, and thus allow
thread-scheduling to happen.
Regards,
Martin
More information about the Python-list
mailing list