Skip to content

Commit 75e93dd

Browse files
committed
Fix it for Windows (I hope)
1 parent bd9f754 commit 75e93dd

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Lib/test/test_interpreters/test_lifecycle.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,27 +185,30 @@ def test_gh_109793(self):
185185
self.assertEqual(proc.returncode, 1)
186186

187187
@support.requires_subprocess()
188-
@unittest.skipIf(sys.platform == "win32", "SIGINT does not work on Windows")
189188
def test_interrupt_thread_with_interpreter(self):
190189
# See GH-126016: Subinterpreters that are created
191190
# in another thread might not have their thread states
192191
# cleaned up if the user interrupted joining with CTRL+C.
193192
import subprocess
194193
import signal
195194

195+
flags = subprocess.CREATE_NEW_PROCESS_GROUP if sys.platform == "win32" else 0
196196
with subprocess.Popen([
197197
sys.executable, "-c",
198198
"import threading, _interpreters\n"
199199
"def run_interp(): _interpreters.run_string(_interpreters.create(),"
200200
"'import time; print(1, flush=True); time.sleep(5)')\n"
201201
"threading.Thread(target=run_interp).start()"
202-
], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) as proc:
202+
], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, creationflags=flags) as proc:
203203
with proc.stdout:
204204
# Make sure that the thread has actually started
205205
self.assertEqual(proc.stdout.read(1), "1")
206206

207207
# Send a KeyboardInterrupt to the process
208-
proc.send_signal(signal.SIGINT)
208+
if sys.platform == "win32":
209+
proc.send_signal(signal.CTRL_C_EVENT)
210+
else:
211+
proc.send_signal(signal.SIGINT)
209212
with proc.stderr:
210213
self.assertIn("KeyboardInterrupt", proc.stderr.read())
211214
proc.wait()

0 commit comments

Comments
 (0)