Skip to content

Commit ce47e3c

Browse files
gh-160700: Propagate InterruptedError from kqueue wait
1 parent c436e8d commit ce47e3c

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

‎Lib/subprocess.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2302,6 +2302,8 @@ def _wait_kqueue(self, timeout):
23022302
_MAXIMUM_WAIT_TIMEOUT)
23032303
try:
23042304
events = kq.control(changelist, 1, max(delay, 0))
2305+
except InterruptedError:
2306+
raise
23052307
except OSError:
23062308
return False
23072309
if events:

‎Lib/test/test_subprocess.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4311,6 +4311,21 @@ def test_kqueue_control_error(self):
43114311
self.assertEqual(p.wait(timeout=support.SHORT_TIMEOUT), 0)
43124312
self.assertTrue(m.called)
43134313

4314+
@unittest.skipIf(not CAN_USE_KQUEUE, reason="needs kqueue() for proc")
4315+
def test_kqueue_control_interrupted_error(self):
4316+
p = subprocess.Popen(self.COMMAND)
4317+
kq_mock = mock.Mock()
4318+
kq_mock.control.side_effect = InterruptedError
4319+
kq_mock.close = mock.Mock()
4320+
try:
4321+
with mock.patch("select.kqueue", return_value=kq_mock):
4322+
with self.assertRaises(InterruptedError):
4323+
p.wait(self.WAIT_TIMEOUT)
4324+
finally:
4325+
p.kill()
4326+
p.wait()
4327+
self.assertTrue(kq_mock.control.called)
4328+
43144329
def assert_wait_race_condition(self, patch_target, real_func):
43154330
# Call pidfd_open() / kqueue(), then terminate the process.
43164331
# Make sure that the wait call (poll() / kqueue.control())

0 commit comments

Comments
 (0)