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

gh-115035: Mark ThreadHandles as non-joinable earlier after forking by colesbury · Pull Request #115042 · python/cpython · GitHub

Repository navigation

gh-115035: Mark ThreadHandles as non-joinable earlier after forking - #115042

Merged
colesbury merged 2 commits into
python:mainfrom
colesbury:gh-115035-thread-handle
Feb 6, 2024
Merged

colesbury merged 2 commits into
python:mainfrom
colesbury:gh-115035-thread-handle

Conversation

colesbury commented Feb 5, 2024 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Contributor

This marks dead ThreadHandles as non-joinable earlier in PyOS_AfterFork_Child() before we execute any Python code. The handles are stored in a global linked list in _PyRuntimeState because fork() affects the entire process.

This marks dead ThreadHandles as non-joinable earlier in
`PyOS_AfterFork_Child()` before we execute any Python code. The handles
are stored in a global linked list in `_PyRuntimeState` because `fork()`
affects the entire process.
colesbury changed the title gh-115035: Mark ThreadHandles as non-joinable earlier gh-115035: Mark ThreadHandles as non-joinable earlier after forking Feb 5, 2024

Copy link
Copy Markdown
Contributor Author

This doesn't call PyThread_update_thread_after_fork(). As far as I can tell, that call did not have any effect: we determine the current thread using PyThread_get_thread_ident_ex() (via get_ident) 1 so there's no way we could have a thread with a stale identifier. And if we don't find a matching thread, we create a new _MainThread() with the correct current identifier (and no handle).

Footnotes

  1. https://github.com/python/cpython/blob/c32bae52904723d99e1f98e2ef54570268d86467/Lib/threading.py#L1725-L1731 ↩

pitrou commented Feb 6, 2024

Copy link
Copy Markdown
Member

As far as I can tell, that call did not have any effect: we determine the current thread using PyThread_get_thread_ident_ex() (via get_ident) 1 so there's no way we could have a thread with a stale identifier.

That's a good point, but then we can probably remove the PyThread_update_thread_after_fork function?

Comment thread Modules/_threadmodule.c
colesbury requested a review from pitrou February 6, 2024 15:51

pitrou 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

Neat, thank you @colesbury !

pitrou commented Feb 6, 2024

Copy link
Copy Markdown
Member

Note: you're a core developer now ;-)

colesbury merged commit b6228b5 into python:main Feb 6, 2024
colesbury deleted the gh-115035-thread-handle branch February 6, 2024 19:45

gpshead commented Feb 7, 2024

Copy link
Copy Markdown
Member

nice refactoring, thanks! happy first-ish merge!

fsc-eriker pushed a commit to fsc-eriker/cpython that referenced this pull request Feb 14, 2024
…king (python#115042)

This marks dead ThreadHandles as non-joinable earlier in
`PyOS_AfterFork_Child()` before we execute any Python code. The handles
are stored in a global linked list in `_PyRuntimeState` because `fork()`
affects the entire process.
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL