Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-132542: Set native thread ID after fork #132701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 20, 2025

Conversation

noamcohen97
Copy link
Contributor

@noamcohen97 noamcohen97 commented Apr 18, 2025

Since most of Python's runtime state, including thread-related data, is only consistent after PyOS_AfterFork_Child() is called, updating native_id in the after_fork handler ensures correctness and aligns with Python’s existing fork-handling mechanisms.

Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

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

Needs a blurb entry.

@ZeroIntensity ZeroIntensity added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Apr 19, 2025
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @ZeroIntensity for commit 6ebd095 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F132701%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Apr 19, 2025
Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

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

LGTM

@serhiy-storchaka serhiy-storchaka added the needs backport to 3.14 bugs and security fixes label May 8, 2025
@noamcohen97 noamcohen97 requested a review from gpshead May 20, 2025 15:58
Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

LGTM. 👍👍

@serhiy-storchaka serhiy-storchaka enabled auto-merge (squash) May 20, 2025 16:15
@serhiy-storchaka serhiy-storchaka merged commit 6b73502 into python:main May 20, 2025
43 checks passed
@miss-islington-app
Copy link

Thanks @noamcohen97 for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 20, 2025
@miss-islington-app
Copy link

Sorry, @noamcohen97 and @serhiy-storchaka, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 6b735023132a4ac9dc5b849d982104eeb1e8bdad 3.13

@bedevere-app
Copy link

bedevere-app bot commented May 20, 2025

GH-134356 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label May 20, 2025
@bedevere-app
Copy link

bedevere-app bot commented May 20, 2025

GH-134361 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label May 20, 2025
serhiy-storchaka pushed a commit that referenced this pull request May 20, 2025
serhiy-storchaka pushed a commit that referenced this pull request May 20, 2025
@noamcohen97 noamcohen97 deleted the fork-tid branch May 20, 2025 17:31
@kulikjak
Copy link
Contributor

kulikjak commented May 21, 2025

Hi, the newly added test fails on systems without native_id:

Traceback (most recent call last):
  File "<string>", line 6, in <module>
    parent_thread_native_id = threading.current_thread().native_id
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: '_MainThread' object has no attribute 'native_id'

(while Lib/threading.py does check for its existence, the test does not)

@noamcohen97
Copy link
Contributor Author

@kulikjak Thank you for noticing. I apologize for that.
I have created #134408 to address the issue.

@serhiy-storchaka Can you please help with merging the fix?

@kulikjak
Copy link
Contributor

No worries, thanks for the fix!

lkollar pushed a commit to lkollar/cpython that referenced this pull request May 26, 2025
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull request Jul 12, 2025
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.

6 participants