Issue 19576: "Non-Python created threads" documentation doesn't mention PyEval_InitThreads() (original) (raw)

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:53 admin set github: 63775
2016-01-03 19:08:17 tzickel set nosy: + tzickelmessages: +
2014-05-04 07:42:40 lolynx set nosy: + lolynxmessages: +
2013-12-13 00:48:00 python-dev set status: open -> closednosy: + python-devmessages: + resolution: fixedstage: resolved
2013-12-13 00:36:30 pitrou set messages: +
2013-12-13 00:35:36 vstinner set messages: +
2013-11-14 08:28:02 vstinner set files: + PyGILState_Ensure.patchkeywords: + patchmessages: +
2013-11-14 01:39:23 pitrou set messages: +
2013-11-13 21:49:30 vstinner create