@@ -81,7 +81,7 @@ def thready():
8181
8282 @threading_helper .requires_working_threading ()
8383 def test_thread_created_in_atexit (self ):
84- source = """
84+ source = """if True:
8585 import atexit
8686 import threading
8787 import time
@@ -96,12 +96,46 @@ def run():
9696 def start_thread():
9797 threading.Thread(target=run).start()
9898 """
99-
100- return_code , stdout , stderr = script_helper .assert_python_ok ("-c" , textwrap .dedent (source ))
99+ return_code , stdout , stderr = script_helper .assert_python_ok ("-c" , source )
101100 self .assertEqual (return_code , 0 )
102101 self .assertEqual (stdout , f"24{ os .linesep } 42{ os .linesep } " .encode ("utf-8" ))
103102 self .assertEqual (stderr , b"" )
104103
104+ @threading_helper .requires_working_threading ()
105+ def test_thread_created_in_atexit_subinterpreter (self ):
106+ import os
107+
108+ try :
109+ from concurrent import interpreters
110+ except ImportError :
111+ self .skipTest ("subinterpreters are not available" )
112+
113+ read , write = os .pipe ()
114+ source = f"""if True:
115+ import atexit
116+ import threading
117+ import time
118+ import os
119+
120+ def run():
121+ os.write({ write } , b'spanish')
122+ time.sleep(1)
123+ os.write({ write } , b'inquisition')
124+
125+ @atexit.register
126+ def start_thread():
127+ threading.Thread(target=run).start()
128+ """
129+ interp = interpreters .create ()
130+ try :
131+ interp .exec (source )
132+
133+ # Close the interpreter to invoke atexit callbacks
134+ interp .close ()
135+ self .assertEqual (os .read (read , 100 ), b"spanishinquisition" )
136+ finally :
137+ os .close (read )
138+ os .close (write )
105139
106140@support .cpython_only
107141class SubinterpreterTest (unittest .TestCase ):
0 commit comments