This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: "Non-Python created threads" documentation doesn't mention PyEval_InitThreads()
Type: Stage: resolved
Components: Documentation Versions: Python 3.3, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: christian.heimes, docs@python, lolynx, pitrou, python-dev, tzickel, vstinner
Priority: normal Keywords: patch

Created on 2013-11-13 21:49 by vstinner, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
PyGILState_Ensure.patch vstinner, 2013-11-14 08:28 review
Messages (8)
msg202787 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2013-11-13 21:49
While working on a unit test for the issue #14432, I hit a bug. My C thread got the GIL with PyGILState_Ensure(), but it was strange because the main Python thread also had the GIL...

Then I saw that gil_created() returned false. The solution is to call PyEval_InitThreads() to create the GIL.

I was reading "Non-Python created threads" documentation, but this section doesn't mention PyEval_InitThreads().

I don't know if it's something new in Python 3.2 with the new GIL.
msg202815 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-11-14 01:39
Perhaps we can fix PyGILState to call PyEval_InitThreads automatically?
msg202821 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2013-11-14 08:28
> Perhaps we can fix PyGILState to call PyEval_InitThreads automatically?

Yes, I had the same idea. Here is a patch to call PyEval_InitThreads() in PyGILState_Ensure() for new threads.
msg205999 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2013-12-13 00:35
So Antoine, what do you think of the fix?
msg206000 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-12-13 00:36
Looks good to me.
msg206002 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-12-13 00:48
New changeset dc4e805ec68a by Victor Stinner in branch 'default':
Close #19576: PyGILState_Ensure() now initializes threads. At startup, Python
http://hg.python.org/cpython/rev/dc4e805ec68a
msg217860 - (view) Author: Jiong Du (lolynx) Date: 2014-05-04 07:42
this patch made a new issue<20891>
msg257426 - (view) Author: (tzickel) * Date: 2016-01-03 19:08
I think that the document regarding PyGILState_Ensure and PyEval_InitThreads should be clarified better, written in issue #26003
History
Date User Action Args
2022-04-11 14:57:53adminsetgithub: 63775
2016-01-03 19:08:17tzickelsetnosy: + tzickel
messages: + msg257426
2014-05-04 07:42:40lolynxsetnosy: + lolynx
messages: + msg217860
2013-12-13 00:48:00python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg206002

resolution: fixed
stage: resolved
2013-12-13 00:36:30pitrousetmessages: + msg206000
2013-12-13 00:35:36vstinnersetmessages: + msg205999
2013-11-14 08:28:02vstinnersetfiles: + PyGILState_Ensure.patch
keywords: + patch
messages: + msg202821
2013-11-14 01:39:23pitrousetmessages: + msg202815
2013-11-13 21:49:30vstinnercreate