FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-39511: PyThreadState_Clear() calls on_delete by vstinner · Pull Request #18296 · python/cpython · GitHub

/ cpython Public

bpo-39511: PyThreadState_Clear() calls on_delete - #18296

Merged
vstinner merged 1 commit into
python:masterfrom
vstinner:zapthreads
Feb 1, 2020
Merged

bpo-39511: PyThreadState_Clear() calls on_delete#18296
vstinner merged 1 commit into
python:masterfrom
vstinner:zapthreads

Conversation

vstinner commented Jan 31, 2020
edited
Loading

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Member Author

Eric snow @ericsnowcurrently already faced this issue when trying to fix https://bugs.python.org/issue36854 with his PR #13219. I managed to work around this issue by clearing the Python thread state later: commit 9da7430.

But to implement https://bugs.python.org/issue39511 correctly (clear singletons at exit), I have to fix this issue.

Copy link
Copy Markdown
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 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM

I only have one suggestion on the wording of the docs.

Comment thread Doc/c-api/init.rst Outdated
Comment on lines 1052 to 1054

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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`.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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 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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL