gh-154836: Fix Popen.wait() with very large timeouts on the pidfd/kqueue wait paths - #154837
Open
calvinrp wants to merge 1 commit into
Open
gh-154836: Fix Popen.wait() with very large timeouts on the pidfd/kqueue wait paths#154837calvinrp wants to merge 1 commit into
calvinrp wants to merge 1 commit into
Conversation
…fd/kqueue wait paths The event-driven wait introduced by pythongh-83069 passes the caller's timeout unclamped to poll() / kqueue.control(), so values that do not fit the C timestamp conversion (float('inf'), sys.maxsize, 1e10, ...) raise OverflowError on Linux and, on macOS/BSD, a misleading "TypeError: timeout must be a real number or None" -- all of which worked on 3.14 and earlier. - Lib/subprocess.py: clamp each wait to _MAXIMUM_WAIT_TIMEOUT (24h, following asyncio's MAXIMUM_SELECT_TIMEOUT precedent) and loop until the real deadline in both _wait_pidfd() and _wait_kqueue(). - Modules/selectmodule.c: only rewrite the kqueue.control() timeout conversion failure into TypeError when the original exception IS a TypeError, exactly like the select()/poll()/devpoll()/epoll() sites, so OverflowError surfaces for out-of-range values. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
BHUVANSH855
reviewed
Jul 28, 2026
BHUVANSH855
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the PR!
I noticed that the only failing required check is the Contributor License Agreement (CLA). It looks like the implementation, and the rest of the CI checks are passing.
Could you please sign the CLA? Once that's done, the required check should pass, and the PR will be ready for code review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Body
Fixes the 3.15 regression where
subprocess.Popen.wait(timeout=...)(andsubprocess.run(..., timeout=...)) fails for very large timeout values suchas
float("inf"),sys.maxsizeor1e10— all accepted on 3.14 andearlier. The event-driven wait introduced by gh-83069 (#144047) passes the
caller's timeout unclamped to
poll()/kqueue.control(); values that donot fit the C timestamp conversion raise
OverflowErroron Linux and, onmacOS/BSD, a misleading
TypeError: timeout must be a real number or None, not float.Changes
Lib/subprocess.py— both_wait_pidfd()and_wait_kqueue()nowclamp each OS-level wait to a new module constant
_MAXIMUM_WAIT_TIMEOUT = 24 * 3600(following asyncio'sMAXIMUM_SELECT_TIMEOUTprecedent,Lib/asyncio/base_events.py) and loopuntil the caller's real deadline, so
TimeoutExpiredis still raised atthe right time and huge-but-legal timeouts never reach the C conversion.
In
_wait_kqueue()the kevent changelist is only submitted on the firstcontrol()call (theKQ_EV_ADD | KQ_EV_ONESHOTregistration persistsacross timed-out waits).
Modules/selectmodule.c— the kqueuecontrol()timeout-conversionfailure is now only rewritten into the "timeout must be a real number or
None"
TypeErrorwhen the original exception is aTypeError, guardedby
PyErr_ExceptionMatches(PyExc_TypeError)exactly like the siblingselect(),poll(),devpoll()andepoll()sites already do. Hugetimeouts now surface the true
OverflowErrorinstead of a false claimthat a float is not a real number.
Tests
Lib/test/test_subprocess.py(FastWaitTestCase):test_wait_huge_timeout(10**10,sys.maxsize,float('inf')),test_run_huge_timeout(therun()/communicate()path), andtest_wait_slices_do_not_expire_early(with the slice limit patched downto 10 ms, a process outliving many slices is still waited for — guards
against a clamp that fires
TimeoutExpiredat the slice boundary). AllPOSIX-gated: the Windows
_waithas a separate, pre-existingint(timeout * 1000)overflow forfloat("inf")that predates 3.15 andis deliberately out of scope here.
Lib/test/test_kqueue.py:test_control_overflowing_timeout— anout-of-range timeout raises
OverflowError, notTypeError; non-numbersstill raise
TypeError.How tested
On macOS (arm64), against a 3.15.0b4 build with the patched
subprocess.pyoverlaid: the three newtest_subprocesstests pass, theentire pre-existing
FastWaitTestCaseand the POSIX wait-related suitestay green, and
wait(timeout=float("inf"))/run(..., timeout=1e10)succeed. The Python-level clamp alone already fixes the user-visible
wait()/run()breakage (the overflowing value never reacheskq.control()). Thetest_kqueueaddition and theOverflowErrorsurfacing require the rebuilt
selectmodule (verified expected-failagainst the unpatched 3.15.0b4 C module); the Linux
_wait_pidfdloop isexercised by the new tests on Linux CI.
Popen.wait(timeout=float("inf"))raisesTypeError: timeout must be a real number or Noneon macOS/BSD (new kqueue wait path) #154836NEWS entry (already in the commit, blurb format)
Misc/NEWS.d/next/Library/2026-07-19-20-00-00.gh-issue-154836.kqWait.rst: