GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-115035: Mark ThreadHandles as non-joinable earlier after forking by colesbury · Pull Request #115042 · python/cpython

Conversation

@colesbury

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

Uh oh!

There was an error while loading. Please reload this page.

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.

  • Issue: Crash in ThreadHandle_dealloc after fork in free-threaded build #115035

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@colesbury
pythongh-115035: Mark ThreadHandles as non-joinable earlier
8130173
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
colesbury requested review from ericsnowcurrently, gpshead and pitrou February 5, 2024 22:22
@bedevere-app bedevere-app Bot added the awaiting review label Feb 5, 2024
@bedevere-app bedevere-app Bot mentioned this pull request Feb 5, 2024
Crash in ThreadHandle_dealloc after fork in free-threaded build #115035
Closed
@colesbury colesbury added the skip news label Feb 5, 2024
@colesbury 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
@colesbury

colesbury commented 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 ↩

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pitrou

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?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

pitrou
pitrou reviewed Feb 6, 2024
View reviewed changes
Comment thread Include/internal/pycore_pythread.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Modules/_threadmodule.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@colesbury
Add comment and remove unused code.
5b8c1c1
@colesbury
colesbury requested a review from pitrou February 6, 2024 15:51
pitrou
pitrou approved these changes Feb 6, 2024
View reviewed changes

@pitrou pitrou left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Neat, thank you @colesbury !

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Feb 6, 2024
@pitrou

pitrou commented Feb 6, 2024

Copy link
Copy Markdown
Member

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

colesbury and itamaro reacted with hooray emoji
All reactions
  • 🎉 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@colesbury
colesbury merged commit b6228b5 into python:main Feb 6, 2024
@bedevere-app bedevere-app Bot removed the awaiting merge label Feb 6, 2024
@colesbury
colesbury deleted the gh-115035-thread-handle branch February 6, 2024 19:45
@gpshead

gpshead commented Feb 7, 2024

Copy link
Copy Markdown
Member

nice refactoring, thanks! happy first-ish merge!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

fsc-eriker pushed a commit to fsc-eriker/cpython that referenced this pull request Feb 14, 2024
@colesbury @fsc-eriker
pythongh-115035: Mark ThreadHandles as non-joinable earlier after for…
dffd892
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@pitrou pitrou pitrou approved these changes
@gpshead gpshead Awaiting requested review from gpshead
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently ericsnowcurrently is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@colesbury @pitrou @gpshead
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.