Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-83069: Use efficient event-drivensubprocess.Popen.wait() on Linux / macOS / BSD#144047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
vstinner merged 68 commits intopython:mainfromgiampaolo:subprocess-fast-wait
Jan 28, 2026
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
68 commits
Select commitHold shift + click to select a range
288e4db
Use pidfd_open() and save the FD as an attribute
giampaoloJan 18, 2026
6e494ca
Create _busy_wait() and move code in there
giampaoloJan 18, 2026
aaf193c
Move existing code in new _blocking_wait() method
giampaoloJan 18, 2026
7cbb0ad
Use _wait_pidfd()
giampaoloJan 18, 2026
d9760c3
Use pidfd_open() not at class level but at method level
giampaoloJan 18, 2026
5fd8eec
Add kqueue() implementation for macOS and BSD
giampaoloJan 18, 2026
100b111
Add docstrings
giampaoloJan 18, 2026
74ac2f4
Be conservative and check for specific error codes
giampaoloJan 18, 2026
fc0cfd6
Document possible failures
giampaoloJan 18, 2026
f282459
Add missing import
giampaoloJan 18, 2026
6125976
Write test for pidfd_open() failing
giampaoloJan 18, 2026
41dc6c0
Write test case for pidfd_open() / kqueue failing. Assert fallback is…
giampaoloJan 18, 2026
73ba380
Write test case for kqueue failing. Assert fallback is used.
giampaoloJan 18, 2026
3c8e603
Move tests in their own class
giampaoloJan 18, 2026
932ae58
Add test for terminated PID race
giampaoloJan 18, 2026
bb5080a
Add test_kqueue_race()
giampaoloJan 19, 2026
f067073
Add test_kqueue_control_error
giampaoloJan 19, 2026
4d96c2f
Add docstring
giampaoloJan 19, 2026
fe05acc
Guard against possible slow test
giampaoloJan 19, 2026
adb444e
Timeout: use math.ceil to avoid truncation
giampaoloJan 19, 2026
4ec17c1
Remove unused exception var
giampaoloJan 19, 2026
e807ba9
Timeout: use math.ceil to avoid truncation
giampaoloJan 19, 2026
1ddc52b
Replace _can_use_kqueue() -> _CAN_USE_KQUEUE
giampaoloJan 19, 2026
645ef6c
Shorten code
giampaoloJan 19, 2026
6ee771b
Use waitpid() + WNOHANG even if process exited to avoid rare race
giampaoloJan 19, 2026
61c6b99
Revert prev change
giampaoloJan 19, 2026
527646d
Use ceil(timeout) to avoid truncation
giampaoloJan 19, 2026
0a8a1b2
Remove check for timeout < 0 + rm test case which didn't make sense.
giampaoloJan 19, 2026
73b97dc
Don't use _blocking_wait() as it has a while loop
giampaoloJan 19, 2026
2d3c3f7
Add docstring
giampaoloJan 19, 2026
4eac42f
Rm _busy_wait()
giampaoloJan 19, 2026
3c156a9
Add comment
giampaoloJan 19, 2026
dac7d3b
Add assert
giampaoloJan 19, 2026
5c7ec2f
Update comments
giampaoloJan 19, 2026
5c29144
Add test for timeout=0
giampaoloJan 19, 2026
4359b07
Update comment about PID reuse race
giampaoloJan 19, 2026
81275c8
Update comment
giampaoloJan 19, 2026
43b500f
Handle rare case where poll() says we're done, but waitpid() doesn't
giampaoloJan 19, 2026
b64e42b
Update Doc/library/subprocess.rst
giampaoloJan 19, 2026
a101406
Add news entry
giampaoloJan 19, 2026
452f8c4
Add entry in Doc/whatsnew/3.15.rst
giampaoloJan 19, 2026
b0c9890
Fix typo
giampaoloJan 19, 2026
27b7c9f
Re-wording
giampaoloJan 19, 2026
e1da996
Raise on timeout < 0 and re-add test case
giampaoloJan 19, 2026
5c78acc
Check if can really use can_use_pidfd() in unit tests
giampaoloJan 19, 2026
df0538a
Check if can really use kqueue() in unit tests
giampaoloJan 19, 2026
6d8e36c
Pre-emptively check whether to use the fast way methods
giampaoloJan 19, 2026
6ba7465
Add test_fast_path_avoid_busy_loop
giampaoloJan 19, 2026
e3c7977
Update comments
giampaoloJan 19, 2026
97cc3be
Fix missing import on Windows
giampaoloJan 19, 2026
c4342e3
Merge branch 'main' into subprocess-fast-wait
giampaoloJan 19, 2026
5d78d24
Try to fix doc build error
giampaoloJan 19, 2026
a916da3
Try to fix doc build error 2
giampaoloJan 19, 2026
86200bd
Try to fix doc build error 3
giampaoloJan 19, 2026
85c38bc
Try to fix doc build error 4
giampaoloJan 19, 2026
3c92c1d
Try to fix doc build error 5
giampaoloJan 19, 2026
33c8b1f
Minor rewordings
giampaoloJan 19, 2026
525c047
Small refact
giampaoloJan 21, 2026
2b931b8
Address review comments (bare assert, don't use ceil())
giampaoloJan 21, 2026
d1c6e91
Address review comments (use test class VARIABLES)
giampaoloJan 21, 2026
3e9d303
Address review comments (add periods in doc)
giampaoloJan 21, 2026
a44b2d7
Merge branch 'main' into subprocess-fast-wait
giampaoloJan 21, 2026
b4f6020
Remove weird unicode char from doc added by accident
giampaoloJan 21, 2026
4e17856
Don't import select on Windows
giampaoloJan 21, 2026
6f6600d
Make kq.control() invocation clearer by passing kwargs
giampaoloJan 21, 2026
37288c6
Revert previous commit
giampaoloJan 21, 2026
300692e
Remove bare assert statements
giampaoloJan 22, 2026
7bee1e9
Merge branch 'main' into subprocess-fast-wait
giampaoloJan 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Update comments
  • Loading branch information
@giampaolo
giampaolo committedJan 19, 2026
commite3c7977298ffe07314bb4751c89027d6357b3c25
9 changes: 5 additions & 4 deletionsLib/subprocess.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2152,8 +2152,9 @@ def _wait_kqueue(self, timeout):
events = kq.control([kev], 1, timeout) # wait
except OSError as err: # should never happen
return False
if not events:
raise TimeoutExpired(self.args, timeout)
else:
if not events:
raise TimeoutExpired(self.args, timeout)
return True
finally:
kq.close()
Expand All@@ -2177,8 +2178,8 @@ def _wait(self, timeout):
# Try efficient wait first.
if self._wait_pidfd(timeout) or self._wait_kqueue(timeout):
# Process is gone. At this point os.waitpid(pid, 0)
# will return immediately, but inveryrare races
# the PID may have been reused.
# will return immediately, but in rare races (e.g.
#long running processes)the PID may have been reused.
# os.waitpid(pid, WNOHANG) ensures we attempt a
# non-blocking reap without blocking indefinitely.
with self._waitpid_lock:
Expand Down
4 changes: 2 additions & 2 deletionsLib/test/test_subprocess.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4105,8 +4105,8 @@ class FastWaitTestCase(BaseTestCase):
CAN_USE_KQUEUE = subprocess._CAN_USE_KQUEUE

def assert_fast_waitpid_error(self, patch_point):
# Emulate a case where pidfd_open()(Linux)or kqueue()
#(BSD/macOS) fails.Busy-poll wait should be used as fallback.
# Emulate a case where pidfd_open() or kqueue() fails.
# Busy-poll wait should be used as fallback.
exc = OSError(errno.EMFILE, os.strerror(errno.EMFILE))
with mock.patch(patch_point, side_effect=exc) as m:
p = subprocess.Popen([sys.executable,
Expand Down
Loading

[8]ページ先頭

©2009-2026 Movatter.jp