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
标题: "Non-Python created threads" documentation doesn't mention PyEval_InitThreads()
类型: Stage: resolved
Components: Documentation Versions: Python 3.3, Python 3.4
process
状态: closed Resolution: fixed
Dependencies: 后续:
分配给: docs@python 抄送列表: christian.heimes, docs@python, lolynx, pitrou, python-dev, tzickel, vstinner
优先级: normal 关键字: patch

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

文件
文件名 上传时间 Description 编辑
PyGILState_Ensure.patch vstinner, 2013-11-14 08:28 review
Messages (8)
msg202787 - (view) Author: STINNER Victor (vstinner) * (Python committer) 日期: 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) 日期: 2013-11-14 01:39
Perhaps we can fix PyGILState to call PyEval_InitThreads automatically?
msg202821 - (view) Author: STINNER Victor (vstinner) * (Python committer) 日期: 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) 日期: 2013-12-13 00:35
So Antoine, what do you think of the fix?
msg206000 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) 日期: 2013-12-13 00:36
Looks good to me.
msg206002 - (view) Author: Roundup Robot (python-dev) (Python triager) 日期: 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) 日期: 2014-05-04 07:42
this patch made a new issue<20891>
msg257426 - (view) Author: (tzickel) * 日期: 2016-01-03 19:08
I think that the document regarding PyGILState_Ensure and PyEval_InitThreads should be clarified better, written in issue #26003
历史
日期 用户 动作 参数
2022-04-11 14:57:53admin修改github: 63775
2016-01-03 19:08:17tzickel修改抄送: + tzickel
消息: + msg257426
2014-05-04 07:42:40lolynx修改抄送: + lolynx
消息: + msg217860
2013-12-13 00:48:00python-dev修改状态: open -> closed

抄送: + python-dev
消息: + msg206002

resolution: fixed
stage: resolved
2013-12-13 00:36:30pitrou修改消息: + msg206000
2013-12-13 00:35:36vstinner修改消息: + msg205999
2013-11-14 08:28:02vstinner修改文件: + PyGILState_Ensure.patch
keywords: + patch
消息: + msg202821
2013-11-14 01:39:23pitrou修改消息: + msg202815
2013-11-13 21:49:30vstinner创建