https://github.com/python/cpython/commit/0b266aaa398b48df3918308cb5a895dd9a0651d9
commit: 0b266aaa398b48df3918308cb5a895dd9a0651d9
branch: 3.13
author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com>
committer: mpage <mp...@cs.stanford.edu>
date: 2024-12-03T10:30:08-08:00
summary:

[3.13] gh-127421: Fix race in test_start_new_thread_failed (GH-127549) (#127574)

gh-127421: Fix race in test_start_new_thread_failed (GH-127549)

Fix race in test_start_new_thread_failed

When we succeed in starting a new thread, for example if setrlimit
was ineffective, we must wait for the newly spawned thread to exit.
Otherwise, we run the risk that the newly spawned thread will race
with runtime finalization and access memory that has already been
clobbered/freed.

`_thread.start_new_thread()` only spawns daemon threads, which the runtime
does not wait for at shutdown, and does not return a handle. Use
`_thread.start_joinable_thread()` and join the resulting handle when
the thread is started successfully.
(cherry picked from commit 13b68e1a61e92a032d255aff5d5af435bbb63e8b)

Co-authored-by: mpage <mp...@meta.com>

files:
M Lib/test/test_threading.py

diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py
index c13d1bd0f81efb..c4cf3e6a14a61c 100644
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -1192,11 +1192,12 @@ def f():
             resource.setrlimit(resource.RLIMIT_NPROC, (0, hard))
 
             try:
-                _thread.start_new_thread(f, ())
+                handle = _thread.start_joinable_thread(f)
             except RuntimeError:
                 print('ok')
             else:
                 print('!skip!')
+                handle.join()
         """
         _, out, err = assert_python_ok("-u", "-c", code)
         out = out.strip()

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to