[New-bugs-announce] [issue5299] PyGILState_Ensure()/PyGILState_Release() documentation incomplete?

Philip Semanchuk report at bugs.python.org
Tue Feb 17 21:43:34 CET 2009


New submission from Philip Semanchuk <osvenskan at users.sourceforge.net>:

The threading API documentation might omit out some important
information about the GIL. 

The GIL can be acquired by explicitly calling PyEval_AcquireLock(). One
can also acquire the GIL by calling PyGILState_Ensure(). The latter
differs from the former in that calling PyGILState_Ensure() when one
already has the GIL will not create deadlock. This is implied; it would
be helpful if this was explicitly stated. 

Likewise, I assume that the Nth call to PyGILState_Release() releases
the GIL, where N = the number of calls made previously to
PyGILState_Ensure(). But I don't know this and the documentation doesn't
make it clear. 

As a first-time user of the API, it makes me nervous to call
PyGILState_Ensure() which acquires the GIL without knowing for sure that
PyGILState_Release() releases it. I can't evaluate my code for logical
correctness, and when dealing with threads and the GIL, neither can I be
sure that timing-dependent bugs will show up in testing. As a result, my
code feels fragile.

I don't understand how the code works well enough to suggest better
documentation. If nothing else, it would be useful to see something that
promises that as long as each call to PyGILState_Ensure() is matched
with a call to PyGILState_Release(), the GIL will take care of itself.

----------
assignee: georg.brandl
components: Documentation
messages: 82366
nosy: georg.brandl, osvenskan
severity: normal
status: open
title: PyGILState_Ensure()/PyGILState_Release() documentation incomplete?
versions: Python 2.4, Python 2.5, Python 2.6, Python 2.7, Python 3.0, Python 3.1

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5299>
_______________________________________


More information about the New-bugs-announce mailing list