Skip to content
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

PidfdChildWatcher runs callbacks on the main thread eventloop and not the currently running loop #94182

Closed
graingert opened this issue Jun 23, 2022 · 6 comments
Labels
topic-asyncio type-bug An unexpected behavior, bug, or error

Comments

@graingert
Copy link
Contributor

graingert commented Jun 23, 2022

as of #93896 and #94593 asyncio.Runner(loop_factory=asyncio.new_event_loop) no longer calls asyncio.set_event_loop() and so the PidfdChildWatcher is never activated

this is unfortunate because it could run asyncio.get_running_loop().add_reader instead

@kumaraditya303
Copy link
Contributor

Wasn't this fixed by #94593?

@graingert
Copy link
Contributor Author

Wasn't this fixed by #94593?

No

@graingert
Copy link
Contributor Author

The purpose of os.open_pidfd is to allow a single event loop running in any thread to monitor processes without needing to interact with another event loop or thread. The pidfdchildwatcher is currently unnecessarily using another loop in another thread

@ezio-melotti ezio-melotti moved this to Todo in asyncio Jul 17, 2022
@graingert
Copy link
Contributor Author

graingert commented Jul 19, 2022

@kumaraditya303 I can demonstrate that the issue is still not resolved by using 5647edb (#94184) - I updated the description to clarify this

gvanrossum pushed a commit that referenced this issue Oct 8, 2022
There is no reason for this watcher to be attached to any particular loop.
This should make it safe to use regardless of the lifetime of the event loop running in the main thread
(relative to other loops).

Co-authored-by: Yury Selivanov <[email protected]>
Co-authored-by: Jelle Zijlstra <[email protected]>
@gvanrossum
Copy link
Member

Thanks for the fix!

I don't think we should backport this (not even to 3.11.1).

Repository owner moved this from Todo to Done in asyncio Oct 8, 2022
carljm added a commit to carljm/cpython that referenced this issue Oct 8, 2022
* main:
  pythongh-68686: Retire eptag ptag scripts (python#98064)
  pythongh-97922: Run the GC only on eval breaker (python#97920)
  GitHub Workflows security hardening (python#96492)
  Add `@ezio-melotti` as codeowner for `.github/`. (python#98079)
  pythongh-97913 Docs: Add walrus operator to the index (python#97921)
  [doc] Fix broken links to C extensions accelerating stdlib modules (python#96914)
  pythongh-97822: Fix http.server documentation reference to test() function (python#98027)
  pythongh-91052: Add PyDict_Unwatch for unwatching a dictionary (python#98055)
  pythonGH-98023: Change default child watcher to PidfdChildWatcher on supported systems (python#98024)
  pythonGH-94182: Run the PidfdChildWatcher on the running loop (python#94184)
carljm added a commit to carljm/cpython that referenced this issue Oct 9, 2022
* main: (5519 commits)
  Minor edits to the Descriptor HowTo Guide (pythonGH-24901)
  Fix link to Lifecycle of a Pull Request in CONTRIBUTING (python#98102)
  pythonGH-94597: deprecate `SafeChildWatcher`, `FastChildWatcher` and `MultiLoopChildWatcher` child watchers  (python#98089)
  Auto-cancel old builds when new commit pushed to branch (python#98009)
  pythongh-95011: Migrate syslog module to Argument Clinic (pythonGH-95012)
  pythongh-68686: Retire eptag ptag scripts (python#98064)
  pythongh-97922: Run the GC only on eval breaker (python#97920)
  GitHub Workflows security hardening (python#96492)
  Add `@ezio-melotti` as codeowner for `.github/`. (python#98079)
  pythongh-97913 Docs: Add walrus operator to the index (python#97921)
  [doc] Fix broken links to C extensions accelerating stdlib modules (python#96914)
  pythongh-97822: Fix http.server documentation reference to test() function (python#98027)
  pythongh-91052: Add PyDict_Unwatch for unwatching a dictionary (python#98055)
  pythonGH-98023: Change default child watcher to PidfdChildWatcher on supported systems (python#98024)
  pythonGH-94182: Run the PidfdChildWatcher on the running loop (python#94184)
  pythongh-92886: make test_ast pass with -O (assertions off) (pythonGH-98058)
  pythongh-92886: make test_coroutines pass with -O (assertions off) (pythonGH-98060)
  pythongh-57179: Add note on symlinks for os.walk (python#94799)
  pythongh-94808: Fix regex on exotic platforms (python#98036)
  pythongh-90085: Remove vestigial -t and -c timeit options (python#94941)
  ...
mpage pushed a commit to mpage/cpython that referenced this issue Oct 11, 2022
…#94184)

There is no reason for this watcher to be attached to any particular loop.
This should make it safe to use regardless of the lifetime of the event loop running in the main thread
(relative to other loops).

Co-authored-by: Yury Selivanov <[email protected]>
Co-authored-by: Jelle Zijlstra <[email protected]>
@serhiy-storchaka
Copy link
Member

This test fails if run separately. See #109862.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-asyncio type-bug An unexpected behavior, bug, or error
Projects
Status: Done
Development

No branches or pull requests

5 participants