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

Open
giampaolo wants to merge68 commits intopython:main
base:main
Choose a base branch
Loading
fromgiampaolo:subprocess-fast-wait

Conversation

@giampaolo
Copy link
Contributor

@giampaologiampaolo commentedJan 19, 2026
edited by github-actionsbot
Loading

This patch replaces the busy-loop mechanism used bysubprocess.Popen.wait() on Linux, BSD, and macOS when atimeout is specified:

  • Linux ≥= 5.3: usesos.pidfd_open() +select.poll()
  • macOS, BSD: usesselect.kqueue() +KQ_FILTER_PROC +KQ_NOTE_EXIT

The kernel wakes us up exactly when the PID terminates or the timeout expires. If the fast-wait mechanisms is not available or fails (e.g. "too many open files"), the function falls back to the traditional busy loop. A similar approach was recently implemented in psutil (seegiampaolo/psutil#2706). While working on that change, I noticed that the subprocess module used essentially the same busy-loop strategy, which motivated this proposal.


📚 Documentation preview 📚:https://cpython-previews--144047.org.readthedocs.build/

soltanoff reacted with heart emoji
Copy link
Member

@vstinnervstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Nice change! I like it. Here is a first review.

cc@gpshead

Comment on lines 4193 to 4194
assertm1.called
assertm2.called
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
assertm1.called
assertm2.called
self.assertTrue(m1.called)
self.assertTrue(m2.called)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You don't want to replaceassert here?

withself.assertRaises(subprocess.TimeoutExpired):
p.wait(timeout=0.0001)
self.assertEqual(p.wait(timeout=support.LONG_TIMEOUT),0)
assertnotm.called
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
assertnotm.called
self.assertFalse(m.called)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You don't want to replaceassert here?

@giampaolo
Copy link
ContributorAuthor

Thanks for the review@vstinner. I addressed your comments.

Copy link
Member

@vstinnervstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM. Thanks for the updates!

Comment on lines 4193 to 4194
assertm1.called
assertm2.called
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You don't want to replaceassert here?

withself.assertRaises(subprocess.TimeoutExpired):
p.wait(timeout=0.0001)
self.assertEqual(p.wait(timeout=support.LONG_TIMEOUT),0)
assertnotm.called
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You don't want to replaceassert here?

@giampaolo
Copy link
ContributorAuthor

Whops! I fixed the remaining bareassert statements.

@vstinner
Copy link
Member

@gpshead: Do you want to double check the change?

@giampaolo
Copy link
ContributorAuthor

giampaolo commentedJan 24, 2026
edited
Loading

In the hope of adding BSD / macOS support forasyncio in the future, I have opened#144211.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@vstinnervstinnervstinner approved these changes

@gpsheadgpsheadAwaiting requested review from gpsheadgpshead is a code owner

@AA-TurnerAA-TurnerAwaiting requested review from AA-TurnerAA-Turner is a code owner

@benjaminpbenjaminpAwaiting requested review from benjaminp

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@giampaolo@vstinner

[8]ページ先頭

©2009-2026 Movatter.jp