Skip to content

Commit e1da996

Browse files
committed
Raise on timeout < 0 and re-add test case
1 parent 27b7c9f commit e1da996

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

Lib/subprocess.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,6 +2122,8 @@ def _wait(self, timeout):
21222122
return self.returncode
21232123

21242124
if timeout is not None:
2125+
if timeout < 0:
2126+
raise TimeoutExpired(self.args, timeout)
21252127
started = _time()
21262128
endtime = started + timeout
21272129

Lib/test/test_subprocess.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ def test_call_timeout(self):
163163
timeout=0.1)
164164

165165
def test_timeout_exception(self):
166+
try:
167+
subprocess.run([sys.executable, '-c', 'import time;time.sleep(9)'], timeout = -1)
168+
except subprocess.TimeoutExpired as e:
169+
self.assertIn("-1 seconds", str(e))
170+
else:
171+
self.fail("Expected TimeoutExpired exception not raised")
166172
try:
167173
subprocess.run([sys.executable, '-c', 'import time;time.sleep(9)'], timeout = 0)
168174
except subprocess.TimeoutExpired as e:

Misc/NEWS.d/next/Library/2026-01-19-16-45-16.gh-issue-83069.0TaeH9.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ event-driven mechanism now waits for process termination, if available:
44
- Linux ≥= 5.3 uses :func:`os.pidfd_open` + :func:`select.poll`
55
- macOS and other BSD variants use :func:`select.kqueue` + ``KQ_FILTER_PROC`` +
66
``KQ_NOTE_EXIT``
7-
- Windows keep using ``WaitForSingleObject`` (unchanged)
7+
- Windows keeps using ``WaitForSingleObject`` (unchanged)
88

99
If none of these mechanisms are available, the function falls back to the
1010
traditional busy loop (non-blocking call and short sleeps).

0 commit comments

Comments
 (0)