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, haypo, lolynx, pitrou, python-dev, tzickel
Priority: normal Keywords: patch

Created on 2013-11-13 21:49 by haypo, last changed 2016-01-03 19:08 by tzickel. This issue is now closed.

Files
File name Uploaded Description Edit
PyGILState_Ensure.patch haypo, 2013-11-14 08:28 review
Messages (8)
msg202787 - (view) Author: STINNER Victor (haypo) * (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 (haypo) * (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 (haypo) * (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) 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
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:36hayposetmessages: + msg205999
2013-11-14 08:28:02hayposetfiles: + PyGILState_Ensure.patch
keywords: + patch
messages: + msg202821
2013-11-14 01:39:23pitrousetmessages: + msg202815
2013-11-13 21:49:30haypocreate