You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[subinterpreters] Make the PyGILState API compatible with multiple interpreters #55124
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2020-05-15.01:26:55.685>created_at=<Date2011-01-15.14:52:39.797>labels= ['expert-subinterpreters', 'type-feature', '3.8', '3.9']
title='[subinterpreters] Make the PyGILState API compatible with multiple interpreters'updated_at=<Date2020-05-15.01:26:55.684>user='https://github.com/pitrou'
Graham - the cases you describe are the things I was saying don't
currently work in my post and wouldn't be helped by Antoine's patch.
Your thoughts on how we could possibly make it work actually parallel
mine (although there may be fun and games with making sure the
respective GILs are acquired and released in an appropriate order when
switching interpreters).
There is only a single GIL, not one per interpreter. And this mustn't
change since some objects are shared and their reference counts
shouldn't be touched concurrently.
Good point - consider that comment revised to refer to the GIL acquisition counter in the thread state struct. It may just be a matter of having ThreadState_Swap complain loudly if the gilstate_counter isn't set to a value it knows how to handle.
The situation there appears to be a case of "Hand off an OS level thread from the creating interpreter to a different subinterpreter. As far as I can tell, calling GILState_Ensure in such a thread will still acquire the GIL of the creating interpreter (or something equally nonsensical)."
It's a single-threaded application using subinterpreters, but all the callbacks from the NumPy code end up hitting the original interpreter that initialised the thread local state in the main thread.
changed the title [-]Make the PyGILState API compatible with multiple interpreters[/-][+][subinterpreters] Make the PyGILState API compatible with multiple interpreters[/+]on May 15, 2020
Activity
pitrou commentedon Jan 17, 2011
There is only a single GIL, not one per interpreter. And this mustn't
change since some objects are shared and their reference counts
shouldn't be touched concurrently.
ncoghlan commentedon Jan 17, 2011
Good point - consider that comment revised to refer to the GIL acquisition counter in the thread state struct. It may just be a matter of having ThreadState_Swap complain loudly if the gilstate_counter isn't set to a value it knows how to handle.
python-dev commentedon Dec 13, 2013
New changeset 5d078b0bae75 by Victor Stinner in branch 'default':
Issue bpo-19787: PyThread_set_key_value() now always set the value
http://hg.python.org/cpython/rev/5d078b0bae75
vstinner commentedon Dec 13, 2013
See also issue bpo-15751.
python-dev commentedon Mar 14, 2016
New changeset e590c632c9fa by Victor Stinner in branch 'default':
Add more checks on the GIL
https://hg.python.org/cpython/rev/e590c632c9fa
pitrou commentedon Jan 23, 2019
Patch probably doesn't apply anymore.
ncoghlan commentedon Jan 28, 2019
A more recent discussion of this on python-dev: https://mail.python.org/pipermail/python-dev/2019-January/156095.html
The situation there appears to be a case of "Hand off an OS level thread from the creating interpreter to a different subinterpreter. As far as I can tell, calling GILState_Ensure in such a thread will still acquire the GIL of the creating interpreter (or something equally nonsensical)."
It's a single-threaded application using subinterpreters, but all the callbacks from the NumPy code end up hitting the original interpreter that initialised the thread local state in the main thread.
vstinner commentedon Dec 11, 2019
See also bpo-1021318: "PyThreadState_Next not thread safe".
[-]Make the PyGILState API compatible with multiple interpreters[/-][+][subinterpreters] Make the PyGILState API compatible with multiple interpreters[/+]vstinner commentedon May 15, 2020
I marked this issue as a duplicate of bpo-15751.