File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 44import unittest
55from test import support
66from test .support import script_helper
7+ from test .support import threading_helper
78
89
910class GeneralTest (unittest .TestCase ):
@@ -46,6 +47,34 @@ def test_atexit_instances(self):
4647 self .assertEqual (res .out .decode ().splitlines (), ["atexit2" , "atexit1" ])
4748 self .assertFalse (res .err )
4849
50+ @threading_helper .requires_working_threading ()
51+ @support .requires_resource ("cpu" )
52+ @unittest .skipUnless (support .Py_GIL_DISABLED , "only meaningful without the GIL" )
53+ def test_atexit_thread_safety (self ):
54+ # GH-126907: atexit was not thread safe on the free-threaded build
55+
56+ # I'm not certain this needs to be in a script runner, but
57+ # let's do it anyway.
58+ code = textwrap .dedent ("""
59+ from threading import Thread
60+
61+ def dummy():
62+ pass
63+
64+
65+ def thready():
66+ for _ in range(100):
67+ atexit.register(dummy)
68+ atexit._clear()
69+ atexit.register(dummy)
70+ atexit.unregister(dummy)
71+
72+
73+ for x in range(100):
74+ Thread(target=thready, args=()).start()
75+ """ )
76+ script_helper .assert_python_ok ("-c" , code )
77+
4978
5079@support .cpython_only
5180class SubinterpreterTest (unittest .TestCase ):
You can’t perform that action at this time.
0 commit comments