-
-
Notifications
You must be signed in to change notification settings - Fork 31.2k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-94182: run the PidfdChildWatcher on the running loop #94184
Merged
gvanrossum
merged 33 commits into
python:main
from
graingert:run-pidfdchildwatcher-on-the-running-loop
Oct 8, 2022
Merged
Changes from 2 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
e49365f
run the PidfdChildWatcher on the running loop
graingert 49cfa81
enable GenericWatcherTests and add a test for pidfd watcher run in a …
graingert 3a3d5e2
fix authspec typo
graingert 60dafa1
Update Lib/test/test_asyncio/test_subprocess.py
graingert 16f1c4e
Update Lib/test/test_asyncio/test_subprocess.py
graingert c8ae89d
Update Lib/test/test_asyncio/test_subprocess.py
graingert 8229efc
Update Lib/test/test_asyncio/test_subprocess.py
graingert 6473022
Merge branch 'main' into run-pidfdchildwatcher-on-the-running-loop
graingert 02190f2
AbstractChildWatcher is called as a context manager
graingert 9607d8e
move GenericWatcherTests into the other unix tests
graingert dad94d9
Merge branch 'main' into run-pidfdchildwatcher-on-the-running-loop
graingert 6e56155
check that asyncio.set_event_loop() was not called
graingert 1037078
📜🤖 Added by blurb_it.
blurb-it[bot] 4e69faf
Merge branch 'main' into run-pidfdchildwatcher-on-the-running-loop
graingert 740e0c2
Merge branch 'main' into run-pidfdchildwatcher-on-the-running-loop
graingert 7721ea1
Merge branch 'main' into run-pidfdchildwatcher-on-the-running-loop
graingert f4f6fc5
Merge branch 'main' of github.com:python/cpython into run-pidfdchildw…
graingert cad5231
Merge branch 'main' into run-pidfdchildwatcher-on-the-running-loop
graingert 5647edb
asyncio.run sets up the policy system asyncio.Runner with a loop_fact…
graingert 102ba29
Update Misc/NEWS.d/next/Library/2022-06-24-08-49-47.gh-issue-94182.Wk…
graingert de21df0
Update Misc/NEWS.d/next/Library/2022-06-24-08-49-47.gh-issue-94182.Wk…
graingert d30824f
move duplicate has_pidfd_support to module global
graingert 978c822
Update Lib/test/test_asyncio/test_subprocess.py
graingert fbeb1a7
Merge branch 'main' into run-pidfdchildwatcher-on-the-running-loop
graingert 6fe4985
Update Lib/test/test_asyncio/test_subprocess.py
graingert 592fcb9
Merge branch 'main' into run-pidfdchildwatcher-on-the-running-loop
graingert d27f174
Merge branch 'main' into run-pidfdchildwatcher-on-the-running-loop
graingert 871507f
Merge branch 'main' into run-pidfdchildwatcher-on-the-running-loop
graingert 5dfc542
Merge branch 'main' into run-pidfdchildwatcher-on-the-running-loop
gvanrossum a4fac11
Merge branch 'main' into run-pidfdchildwatcher-on-the-running-loop
gvanrossum fc2e400
Update Misc/NEWS.d/next/Library/2022-06-24-08-49-47.gh-issue-94182.Wk…
1st1 65a2db6
Update Misc/NEWS.d/next/Library/2022-06-24-08-49-47.gh-issue-94182.Wk…
1st1 d25f852
Merge branch 'main' into run-pidfdchildwatcher-on-the-running-loop
JelleZijlstra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -712,7 +712,7 @@ def setUp(self): | |
self.set_event_loop(self.loop) | ||
|
||
|
||
class GenericWatcherTests: | ||
class GenericWatcherTests(test_utils.TestCase): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this test wasn't enabled? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I split this fix out, so this PR is easier to review: #95009 |
||
|
||
def test_create_subprocess_fails_with_inactive_watcher(self): | ||
|
||
|
@@ -727,9 +727,42 @@ async def execute(): | |
|
||
watcher.add_child_handler.assert_not_called() | ||
|
||
self.assertIsNone(self.loop.run_until_complete(execute())) | ||
self.assertIsNone(asyncio.run(execute())) | ||
|
||
|
||
def has_pidfd_support(): | ||
if not hasattr(os, 'pidfd_open'): | ||
return False | ||
try: | ||
os.close(os.pidfd_open(os.getpid())) | ||
except OSError: | ||
return False | ||
return True | ||
|
||
@unittest.skipUnless( | ||
has_pidfd_support(), | ||
"operating system does not support pidfds", | ||
) | ||
def test_create_subprocess_with_pidfd(self): | ||
async def in_thread(): | ||
proc = await asyncio.create_subprocess_exec( | ||
*args, | ||
graingert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
stdin=subprocess.PIPE, | ||
stdout=subprocess.PIPE, | ||
) | ||
stdout, stderr = await proc.communicate(b"some data") | ||
return proc.returncode, stdout | ||
|
||
async def main(): | ||
return await asyncio.to_thread(asyncio.run, in_thread()) | ||
|
||
asyncio.set_child_watcher(PidfdChildWatcher()) | ||
graingert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
try: | ||
returncode, stdout = asyncio.run(main()) | ||
self.assertEqual(returncode, 0) | ||
self.assertEqual(stdout, b'some data') | ||
finally: | ||
asyncio.set_child_watcher(None) | ||
|
||
|
||
if __name__ == '__main__': | ||
graingert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious why we can't pass the loop as an argument as well? (Though maybe that creates an unhealthy self-reference to the loop.)