{{ message }}
bpo-39511: PyThreadState_Clear() calls on_delete#18296
Merged
vstinner merged 1 commit intopython:masterfrom Feb 1, 2020
vstinner:zapthreads
Merged
bpo-39511: PyThreadState_Clear() calls on_delete#18296vstinner merged 1 commit intopython:masterfrom vstinner:zapthreads
vstinner merged 1 commit intopython:masterfrom
vstinner:zapthreads
Conversation
Member
Author
Member
Author
|
I decided to not document the change in What's New in Python 3.9 since I don't think that PyThreadState_Clear() should be called directly. By the way, I'm not sure why it's documented at all nor why it's a public function. For me, it belongs more to the internal C API. |
ericsnowcurrently
approved these changes
Jan 31, 2020
Member
ericsnowcurrently
left a comment
There was a problem hiding this comment.
LGTM
I only have one suggestion on the wording of the docs.
Comment on lines
1052
to
1054
Member
There was a problem hiding this comment.
This usage of "responsible" could be confusing. Consider instead:
This function now calls the :c:member:`PyThreadState.on_delete`
callback. Previously, that happened in :c:func:`PyThreadState_Delete`.
Member
Author
There was a problem hiding this comment.
Thanks, I updated the doc.
PyThreadState.on_delete is a callback used to notify Python when a thread completes. _thread._set_sentinel() function creates a lock which is released when the thread completes. It sets on_delete callback to the internal release_sentinel() function. This lock is known as Threading._tstate_lock in the threading module. The release_sentinel() function uses the Python C API. The problem is that on_delete is called late in the Python finalization, when the C API is no longer fully working. The PyThreadState_Clear() function now calls the PyThreadState.on_delete callback. Previously, that happened in PyThreadState_Delete(). The release_sentinel() function is now called when the C API is still fully working.
This was referenced May 13, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

PyThreadState.on_delete is a callback used to notify Python when a
thread completes. _thread._set_sentinel() function creates a lock
which is released when the thread completes. It sets on_delete
callback to the internal release_sentinel() function. This lock is
known as Threading._tstate_lock in the threading module.
The release_sentinel() function uses the Python C API. The problem is
that on_delete is called late in the Python finalization, when the C
API is no longer fully working.
The PyThreadState_Clear() function is now responsible to call
PyThreadState.on_delete callback. Previously, PyThreadState_Delete()
was responsible for that.
The release_sentinel() function is now called when the C API is still
fully working.
https://bugs.python.org/issue39511