Closed
Labels
3.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of lifeinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
Description
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 = None
closed_at = <Date 2019-04-14.02:49:46.980>
created_at = <Date 2019-03-25.22:14:35.939>
labels = ['interpreter-core', '3.7', '3.8']
title = 'Document that PyEval_RestoreThread and PyGILState_Ensure can terminate the calling thread'
updated_at = <Date 2019-04-14.02:49:46.980>
user = 'https://github.com/pablogsal'bugs.python.org fields:
activity = <Date 2019-04-14.02:49:46.980>
actor = 'pablogsal'
assignee = 'none'
closed = True
closed_date = <Date 2019-04-14.02:49:46.980>
closer = 'pablogsal'
components = ['Interpreter Core']
creation = <Date 2019-03-25.22:14:35.939>
creator = 'pablogsal'
dependencies = []
files = []
hgrepos = []
issue_num = 36427
keywords = ['patch']
message_count = 11.0
messages = ['338826', '338827', '338828', '338830', '338831', '338832', '339153', '339154', '339156', '340167', '340178']
nosy_count = 4.0
nosy_names = ['pitrou', 'vstinner', 'eric.snow', 'pablogsal']
pr_nums = ['12541', '12820']
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue36427'
versions = ['Python 3.7', 'Python 3.8']Metadata
Metadata
Assignees
Labels
3.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of lifeinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
Activity
pablogsal commentedon Mar 25, 2019
Currently PyEval_RestoreThread and its callers (mainly PyGILState_Ensure) can terminate the thread if the interpreter is finalizing:
This behaviour that protects against problems due to daemon threads registered with the interpreter can be *very* surprising for C-extensions that are using these functions to implement callbacks that can call into Python. These callbacks threads are not owned by the interpreter and are usually joined by someone else, ending in deadlocks in many situations.
I propose to add a warning to the documentation to inform users about this situation.
vstinner commentedon Mar 25, 2019
_Py_IsFinalizing() check is redundant :-)
vstinner commentedon Mar 25, 2019
I really dislike the design of daemon threads. If it would be only me, I would prefer this nasty feature causing so much issues at Python shutdown.
pablogsal commentedon Mar 25, 2019
Well, given that this happens as well in Python3.7 and before, at least we should document it and we can think about changing it in the future. But for now, but I suggest keeping both PRs separated (in case we really want to change anything).
vstinner commentedon Mar 25, 2019
Right. It was just a general comment :-)
pablogsal commentedon Mar 25, 2019
ericsnowcurrently commentedon Mar 29, 2019
Related:
ericsnowcurrently commentedon Mar 29, 2019
Not really:
running finalization
ericsnowcurrently commentedon Mar 29, 2019
s/interpreter/runtime/
Most likely (guaranteed?) it will be in the main interpreter, but it is actually not triggered by interpreter finalization (though it probably should be; I've opened bpo-36479).
pablogsal commentedon Apr 13, 2019
New changeset fde9b33 by Pablo Galindo in branch 'master':
bpo-36427: Document that PyEval_RestoreThread and PyGILState_Ensure can terminate the calling thread (GH-12541)
fde9b33
pablogsal commentedon Apr 14, 2019
New changeset 7723d05 by Pablo Galindo in branch '3.7':
[3.7] bpo-36427: Document that PyEval_RestoreThread and PyGILState_Ensure can terminate the calling thread (GH-12541) (GH-12820)
7723d05