mirror of
https://github.com/python/cpython.git
synced 2025-10-22 01:14:01 +00:00
[3.13] gh-132542: Set native thread ID after fork (GH-132701) (GH-134361)
(cherry picked from commit 6b73502313
)
This commit is contained in:
parent
bad9f63f6c
commit
aebbbaffe8
3 changed files with 32 additions and 0 deletions
|
@ -1208,6 +1208,34 @@ def f():
|
|||
self.assertEqual(err, b'')
|
||||
|
||||
|
||||
@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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue