Skip to content

bpo-35621: Support running subprocesses in asyncio when loop is executed in non-main thread #14344

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

Merged
merged 17 commits into from
Jun 30, 2019

Conversation

asvetlov
Copy link
Contributor

@asvetlov asvetlov commented Jun 24, 2019

The resurrection of #13630
Now without dangling threads in tests :)

https://bugs.python.org/issue35621

@asvetlov
Copy link
Contributor Author

I tested it with manual adding 1-second timeout in spawned waiter threads to emulate slow test machine.
After making sure that ./python -Werror -m test -v --fail-env-changed test_asyncio doesn't produce an error I removed the sleep.

@@ -1035,11 +1052,6 @@ def __exit__(self, a, b, c):
def add_child_handler(self, pid, callback, *args):
assert self._forks, "Must use the context manager"

if self._loop is None:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The check is replaced by watcher.is_active() call in subprocess transport

Copy link
Member

@1st1 1st1 left a comment

Choose a reason for hiding this comment

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

LGTM overall. Thanks for pushing this through, Andrew.

@asvetlov
Copy link
Contributor Author

Thanks for review!

@asvetlov asvetlov merged commit 0d671c0 into python:master Jun 30, 2019
@miss-islington
Copy link
Contributor

Thanks @asvetlov for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒⛏🤖

@asvetlov asvetlov deleted the threaded-waiter branch June 30, 2019 09:55
@bedevere-bot
Copy link

GH-14484 is a backport of this pull request to the 3.8 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 30, 2019
…ted in non-main thread (pythonGH-14344)

(cherry picked from commit 0d671c0)

Co-authored-by: Andrew Svetlov <[email protected]>
miss-islington added a commit that referenced this pull request Jun 30, 2019
…ted in non-main thread (GH-14344)

(cherry picked from commit 0d671c0)

Co-authored-by: Andrew Svetlov <[email protected]>
lisroach pushed a commit to lisroach/cpython that referenced this pull request Sep 10, 2019
DinoV pushed a commit to DinoV/cpython that referenced this pull request Jan 14, 2020
link2xt added a commit to chatmail/core that referenced this pull request May 19, 2023
With Python 3.7 asynchronous tests randomly fail
with "RuntimeError: Event loop is closed" during shutdown.
Backtrace of the error includes `SafeChildWatcher` calls.

Python 3.8 has replaced `SafeChildWatcher`
with a new `ThreadedChildWatcher` by default [1]
as a bugfix for
"asyncio.create_subprocess_exec() only works with main event loop" bug [2].

Python 3.7 scheduled end of life is 2023-06-27
according to <https://devguide.python.org/versions/>.

[1] python/cpython#14344
[2] https://bugs.python.org/issue35621
link2xt added a commit to chatmail/core that referenced this pull request May 19, 2023
With Python 3.7 asynchronous tests randomly fail
with "RuntimeError: Event loop is closed" during shutdown.
Backtrace of the error includes `SafeChildWatcher` calls.

Python 3.8 has replaced `SafeChildWatcher`
with a new `ThreadedChildWatcher` by default [1]
as a bugfix for
"asyncio.create_subprocess_exec() only works with main event loop" bug [2].

Python 3.7 scheduled end of life is 2023-06-27
according to <https://devguide.python.org/versions/>.

[1] python/cpython#14344
[2] https://bugs.python.org/issue35621
link2xt added a commit to chatmail/core that referenced this pull request May 20, 2023
With Python 3.7 asynchronous tests randomly fail
with "RuntimeError: Event loop is closed" during shutdown.
Backtrace of the error includes `SafeChildWatcher` calls.

Python 3.8 has replaced `SafeChildWatcher`
with a new `ThreadedChildWatcher` by default [1]
as a bugfix for
"asyncio.create_subprocess_exec() only works with main event loop" bug [2].

Python 3.7 scheduled end of life is 2023-06-27
according to <https://devguide.python.org/versions/>.

[1] python/cpython#14344
[2] https://bugs.python.org/issue35621
link2xt added a commit to chatmail/core that referenced this pull request May 21, 2023
With Python 3.7 asynchronous tests randomly fail
with "RuntimeError: Event loop is closed" during shutdown.
Backtrace of the error includes `SafeChildWatcher` calls.

Python 3.8 has replaced `SafeChildWatcher`
with a new `ThreadedChildWatcher` by default [1]
as a bugfix for
"asyncio.create_subprocess_exec() only works with main event loop" bug [2].

Python 3.7 scheduled end of life is 2023-06-27
according to <https://devguide.python.org/versions/>.

[1] python/cpython#14344
[2] https://bugs.python.org/issue35621
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants