Skip to content

Commit 2f5073c

Browse files
committed
Add a test case.
1 parent 8f9e675 commit 2f5073c

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

Lib/test/test_threading.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from test.support import threading_helper, requires_subprocess, requires_gil_enabled
77
from test.support import verbose, cpython_only, os_helper
88
from test.support.import_helper import ensure_lazy_imports, import_module
9-
from test.support.script_helper import assert_python_ok, assert_python_failure
9+
from test.support.script_helper import assert_python_ok, assert_python_failure, spawn_python
1010
from test.support import force_not_colorized
1111

1212
import random
@@ -2083,6 +2083,32 @@ def test_dummy_thread_on_interpreter_shutdown(self):
20832083
self.assertEqual(out, b"")
20842084
self.assertEqual(err, b"")
20852085

2086+
@requires_subprocess()
2087+
def test_keyboard_interrupt_during_threading_shutdown(self):
2088+
import subprocess
2089+
source = f"""
2090+
from threading import Thread
2091+
import time
2092+
import os
2093+
2094+
2095+
def test():
2096+
print('a', flush=True, end='')
2097+
time.sleep(10)
2098+
2099+
2100+
for _ in range(3):
2101+
Thread(target=test).start()
2102+
"""
2103+
2104+
with spawn_python("-c", source, stderr=subprocess.PIPE) as proc:
2105+
self.assertEqual(proc.stdout.read(3), b'aaa')
2106+
proc.send_signal(signal.SIGINT)
2107+
proc.stderr.flush()
2108+
error = proc.stderr.read()
2109+
self.assertIn(b"KeyboardInterrupt", error)
2110+
self.assertIn(b"threading shutdown", error)
2111+
20862112

20872113
class ThreadRunFail(threading.Thread):
20882114
def run(self):

0 commit comments

Comments
 (0)