[Python-Dev] [Python-checkins] cpython: PyGILState_Ensure(), PyGILState_Release(), PyGILState_GetThisThreadState() are
Victor Stinner
victor.stinner at haypocalc.com
Sat Apr 30 14:06:33 CEST 2011
Le mercredi 27 avril 2011 à 20:18 -0400, Jim Jewett a écrit :
> Would it be a problem to make them available a no-ops?
>
> On 4/26/11, victor.stinner <python-checkins at python.org> wrote:
> > http://hg.python.org/cpython/rev/75503c26a17f
> > changeset: 69584:75503c26a17f
> > user: Victor Stinner <victor.stinner at haypocalc.com>
> > date: Tue Apr 26 23:34:58 2011 +0200
> > summary:
> > PyGILState_Ensure(), PyGILState_Release(), PyGILState_GetThisThreadState()
> > are
> > not available if Python is compiled without threads.
Oh, I realized that PyGILState_STATE may also be included only if Python
is compiled with threads.
--
PyGILState_Ensure() and PyGILState_Release() could be no-op yes, it
would simplify the usage of these functions. For example:
#ifdef WITH_THREAD
PyGILState_STATE gil;
#endif
fprintf(stderr, "object : ");
#ifdef WITH_THREAD
gil = PyGILState_Ensure();
#endif
(void)PyObject_Print(op, stderr, 0);
#ifdef WITH_THREAD
PyGILState_Release(gil);
#endif
--
Even without threads, a Python process has a PyThreadState structure, so
PyGILState_GetThisThreadState() can be patched to work even if Python is
compiled without threads.
--
Would you like to work on such patch? Or at least open an issue?
Victor
More information about the Python-Dev
mailing list