From ce47e3c28fea3bc7f7062c618bea96c283d5f7be Mon Sep 17 00:00:00 2001 From: adhinaik13 <22je1052@iitism.ac.in> Date: Mon, 26 Oct 2026 20:23:53 +0530 Subject: [PATCH 1/2] gh-160700: Propagate InterruptedError from kqueue wait --- Lib/subprocess.py | 2 ++ Lib/test/test_subprocess.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/Lib/subprocess.py b/Lib/subprocess.py index e2dac4938d57d28..9858bb246f65f33 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -2302,6 +2302,8 @@ def _wait_kqueue(self, timeout): _MAXIMUM_WAIT_TIMEOUT) try: events = kq.control(changelist, 1, max(delay, 0)) + except InterruptedError: + raise except OSError: return False if events: diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index dedd3cc0e9e8675..cbe33f170a2e61e 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -4311,6 +4311,21 @@ def test_kqueue_control_error(self): self.assertEqual(p.wait(timeout=support.SHORT_TIMEOUT), 0) self.assertTrue(m.called) + @unittest.skipIf(not CAN_USE_KQUEUE, reason="needs kqueue() for proc") + def test_kqueue_control_interrupted_error(self): + p = subprocess.Popen(self.COMMAND) + kq_mock = mock.Mock() + kq_mock.control.side_effect = InterruptedError + kq_mock.close = mock.Mock() + try: + with mock.patch("select.kqueue", return_value=kq_mock): + with self.assertRaises(InterruptedError): + p.wait(self.WAIT_TIMEOUT) + finally: + p.kill() + p.wait() + self.assertTrue(kq_mock.control.called) + def assert_wait_race_condition(self, patch_target, real_func): # Call pidfd_open() / kqueue(), then terminate the process. # Make sure that the wait call (poll() / kqueue.control()) From 95bcfc02935e7ec8ef1c3f49881a8a60acb42732 Mon Sep 17 00:00:00 2001 From: adhinaik13 <22je1052@iitism.ac.in> Date: Mon, 26 Oct 2026 20:50:12 +0530 Subject: [PATCH 2/2] gh-160700: Add NEWS entry --- .../Library/2026-10-26-23-45-00.gh-issue-160700.R7mQ2x.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2026-10-26-23-45-00.gh-issue-160700.R7mQ2x.rst diff --git a/Misc/NEWS.d/next/Library/2026-10-26-23-45-00.gh-issue-160700.R7mQ2x.rst b/Misc/NEWS.d/next/Library/2026-10-26-23-45-00.gh-issue-160700.R7mQ2x.rst new file mode 100644 index 000000000000000..89b5c39ac17fa4e --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-10-26-23-45-00.gh-issue-160700.R7mQ2x.rst @@ -0,0 +1,3 @@ +Propagate :exc:`InterruptedError` from :meth:`subprocess.Popen.wait` when +waiting with ``kqueue`` instead of swallowing it as an ordinary operating +system error.