Skip to content

Commit 78cf6ac

Browse files
committed
Manually call os.kill to interrupt
This works around an issue with `subprocess` on Windows.
1 parent 49ce403 commit 78cf6ac

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

tests/tests/test_database_backend.py

+4-15
Original file line numberDiff line numberDiff line change
@@ -1199,15 +1199,6 @@ def start_worker(
11991199
self.processes.append(p)
12001200
return p
12011201

1202-
@staticmethod
1203-
def _get_ctrl_c_signal() -> int:
1204-
"""
1205-
Windows uses a different signal for CTRL-C than Unix.
1206-
"""
1207-
if hasattr(signal, "CTRL_C_EVENT"):
1208-
return cast(int, signal.CTRL_C_EVENT)
1209-
return signal.SIGINT
1210-
12111202
def test_run_subprocess(self) -> None:
12121203
result = test_tasks.noop_task.enqueue()
12131204
process = self.start_worker(["--batch"])
@@ -1232,7 +1223,7 @@ def test_interrupt_no_tasks(self) -> None:
12321223

12331224
def test_interrupt_signals(self) -> None:
12341225
for sig in [
1235-
self._get_ctrl_c_signal(),
1226+
signal.SIGINT, # ctrl-c
12361227
signal.SIGTERM,
12371228
]:
12381229
with self.subTest(sig):
@@ -1246,7 +1237,7 @@ def test_interrupt_signals(self) -> None:
12461237
result.refresh()
12471238
self.assertEqual(result.status, ResultStatus.RUNNING)
12481239

1249-
process.send_signal(sig)
1240+
os.kill(process.pid, sig)
12501241

12511242
process.wait(timeout=1)
12521243

@@ -1257,8 +1248,6 @@ def test_interrupt_signals(self) -> None:
12571248
self.assertEqual(result.status, ResultStatus.COMPLETE)
12581249

12591250
def test_repeat_ctrl_c(self) -> None:
1260-
ctrl_c_signal = self._get_ctrl_c_signal()
1261-
12621251
result = test_tasks.hang.enqueue()
12631252

12641253
process = self.start_worker()
@@ -1269,15 +1258,15 @@ def test_repeat_ctrl_c(self) -> None:
12691258
result.refresh()
12701259
self.assertEqual(result.status, ResultStatus.RUNNING)
12711260

1272-
process.send_signal(ctrl_c_signal)
1261+
os.kill(process.pid, signal.SIGINT)
12731262

12741263
time.sleep(0.5)
12751264

12761265
self.assertIsNone(process.poll())
12771266
result.refresh()
12781267
self.assertEqual(result.status, ResultStatus.RUNNING)
12791268

1280-
process.send_signal(ctrl_c_signal)
1269+
os.kill(process.pid, signal.SIGINT)
12811270

12821271
process.wait(timeout=2)
12831272

0 commit comments

Comments
 (0)