Skip to content

Commit 599a075

Browse files
committed
Enhance test for native thread ID after fork to validate parent thread ID consistency
1 parent 19b7d6c commit 599a075

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Lib/test/test_threading.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,17 +1282,21 @@ def test_native_id_after_fork(self):
12821282
import threading
12831283
import os
12841284
1285-
print(threading.current_thread().native_id, flush=True)
1286-
assert threading.current_thread().native_id == threading.get_native_id()
1285+
parent_thread_native_id = threading.current_thread().native_id
1286+
print(parent_thread_native_id, flush=True)
1287+
assert parent_thread_native_id == threading.get_native_id()
12871288
if os.fork() == 0:
12881289
print(threading.current_thread().native_id, flush=True)
12891290
assert threading.current_thread().native_id == threading.get_native_id()
1291+
else:
1292+
assert parent_thread_native_id == threading.current_thread().native_id
1293+
assert parent_thread_native_id == threading.get_native_id()
12901294
"""
12911295
rc, out, err = assert_python_ok('-c', script)
12921296
self.assertEqual(rc, 0)
12931297
self.assertEqual(err, b"")
12941298
native_ids = out.strip().splitlines()
1295-
self.assertEqual(len(native_ids), 2)
1299+
self.assertEqual(len(native_ids), 3)
12961300
self.assertNotEqual(native_ids[0], native_ids[1])
12971301

12981302
class ThreadJoinOnShutdown(BaseTestCase):

0 commit comments

Comments
 (0)