Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[3.14] gh-132542: Set native thread ID after fork (GH-132701)#134356

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletionsLib/test/test_threading.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1352,6 +1352,34 @@ def do_flush(*args, **kwargs):
''')
assert_python_ok("-c", script)

@skip_unless_reliable_fork
def test_native_id_after_fork(self):
script = """if True:
import threading
import os
from test import support

parent_thread_native_id = threading.current_thread().native_id
print(parent_thread_native_id, flush=True)
assert parent_thread_native_id == threading.get_native_id()
childpid = os.fork()
if childpid == 0:
print(threading.current_thread().native_id, flush=True)
assert threading.current_thread().native_id == threading.get_native_id()
else:
try:
assert parent_thread_native_id == threading.current_thread().native_id
assert parent_thread_native_id == threading.get_native_id()
finally:
support.wait_process(childpid, exitcode=0)
"""
rc, out, err = assert_python_ok('-c', script)
self.assertEqual(rc, 0)
self.assertEqual(err, b"")
native_ids = out.strip().splitlines()
self.assertEqual(len(native_ids), 2)
self.assertNotEqual(native_ids[0], native_ids[1])

class ThreadJoinOnShutdown(BaseTestCase):

def _run_and_join(self, script):
Expand Down
2 changes: 2 additions & 0 deletionsLib/threading.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -951,6 +951,8 @@ def _after_fork(self, new_ident=None):
# This thread is alive.
self._ident = new_ident
assert self._os_thread_handle.ident == new_ident
if _HAVE_THREAD_NATIVE_ID:
self._set_native_id()
else:
# Otherwise, the thread is dead, Jim. _PyThread_AfterFork()
# already marked our handle done.
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
Update :attr:`Thread.native_id <threading.Thread.native_id>` after
:manpage:`fork(2)` to ensure accuracy. Patch by Noam Cohen.
Loading

[8]ページ先頭

©2009-2025 Movatter.jp