@@ -1855,6 +1855,7 @@ def test_new_config(self):
18551855 allow_threads = True ,
18561856 allow_daemon_threads = False ,
18571857 check_multi_interp_extensions = True ,
1858+ can_handle_signals = True ,
18581859 gil = 'own' ,
18591860 ),
18601861 'legacy' : types .SimpleNamespace (
@@ -1864,6 +1865,7 @@ def test_new_config(self):
18641865 allow_threads = True ,
18651866 allow_daemon_threads = True ,
18661867 check_multi_interp_extensions = bool (Py_GIL_DISABLED ),
1868+ can_handle_signals = False ,
18671869 gil = 'shared' ,
18681870 ),
18691871 'empty' : types .SimpleNamespace (
@@ -1873,6 +1875,7 @@ def test_new_config(self):
18731875 allow_threads = False ,
18741876 allow_daemon_threads = False ,
18751877 check_multi_interp_extensions = False ,
1878+ can_handle_signals = False ,
18761879 gil = 'default' ,
18771880 ),
18781881 }
@@ -2134,6 +2137,7 @@ def test_get_config(self):
21342137 with self .subTest ('main' ):
21352138 expected = _interpreters .new_config ('legacy' )
21362139 expected .gil = 'own'
2140+ expected .can_handle_signals = True
21372141 if Py_GIL_DISABLED :
21382142 expected .check_multi_interp_extensions = False
21392143 interpid , * _ = _interpreters .get_main ()
@@ -2360,6 +2364,37 @@ def test_set___main___attrs(self):
23602364 )
23612365 self .assertEqual (rc , 0 )
23622366
2367+ def test_interpreter_handles_signals (self ):
2368+ import subprocess
2369+ import sys
2370+ import signal
2371+
2372+ interp_source = """if True:
2373+ import sys
2374+ import time
2375+
2376+ sys.stdout.write('x')
2377+ sys.stdout.flush()
2378+ time.sleep(10)
2379+ print("should never happen", flush=True)
2380+ """
2381+
2382+ source = f"""if True:
2383+ from concurrent import interpreters
2384+
2385+ interp = interpreters.create()
2386+ interp.exec('''{ interp_source } ''')
2387+ """
2388+
2389+ proc = subprocess .Popen ([sys .executable , '-c' , source ],
2390+ stdin = subprocess .PIPE , stdout = subprocess .PIPE ,
2391+ stderr = subprocess .PIPE , close_fds = True )
2392+ self .assertEqual (proc .stdout .read (1 ), b'x' )
2393+ proc .send_signal (signal .SIGINT )
2394+ stdout , stderr = proc .communicate ()
2395+ self .assertEqual (stdout , b"" )
2396+ self .assertIn (b"KeyboardInterrupt" , stderr )
2397+
23632398
23642399if __name__ == '__main__' :
23652400 # Test needs to be a package, so we can do relative imports.
0 commit comments