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

Inconsistent documentation about calling subprocess inside async function in a child thread #108224

Closed
temach opened this issue Aug 21, 2023 · 1 comment
Labels
3.11 only security fixes 3.12 bugs and security fixes 3.13 bugs and security fixes docs Documentation in the Doc dir topic-asyncio

Comments

@temach
Copy link
Contributor

temach commented Aug 21, 2023

Documentation

This page states: https://docs.python.org/3/library/asyncio-dev.html#concurrency-and-multithreading

To handle signals and to execute subprocesses, the event loop must be run in the main thread.

For me this means that if I want to use subprocess call my async function must be triggered by loop on the main thread. In other words async functions can not call subprocess when running in child thread.

However this page states: https://docs.python.org/3/library/asyncio-subprocess.html#subprocess-and-threads

Standard asyncio event loop supports running subprocesses from different threads by default.

To me this means that I can spawn a child thread, call async function inside it, and that async function is free to call subprocess without problems.

Linked PRs

@temach temach added the docs Documentation in the Doc dir label Aug 21, 2023
@AA-Turner AA-Turner added topic-asyncio 3.11 only security fixes 3.12 bugs and security fixes 3.13 bugs and security fixes labels Aug 21, 2023
@gvanrossum
Copy link
Member

Looks like the line in asyncio-dev.rst is just wrong. It should only require running in the main thread for handling signals. Feel free to submit a doc PR.

gvanrossum pushed a commit that referenced this issue Aug 21, 2023
(Spawning subprocesses does not require the event loop to run in the main thread -- only signal handling does.)
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Aug 21, 2023
(Spawning subprocesses does not require the event loop to run in the main thread -- only signal handling does.)
(cherry picked from commit 1cc391d)

Co-authored-by: temach <tematibr@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Aug 21, 2023
(Spawning subprocesses does not require the event loop to run in the main thread -- only signal handling does.)
(cherry picked from commit 1cc391d)

Co-authored-by: temach <tematibr@gmail.com>
Yhg1s pushed a commit that referenced this issue Aug 21, 2023
gh-108224: Fix asyncio doc inconsistency (GH-108230)

(Spawning subprocesses does not require the event loop to run in the main thread -- only signal handling does.)
(cherry picked from commit 1cc391d)

Co-authored-by: temach <tematibr@gmail.com>
gvanrossum pushed a commit that referenced this issue Aug 21, 2023
(Spawning subprocesses does not require the event loop to run in the main thread -- only signal handling does.)

(cherry picked from commit 1cc391d)

Co-authored-by: temach <tematibr@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only security fixes 3.12 bugs and security fixes 3.13 bugs and security fixes docs Documentation in the Doc dir topic-asyncio
Projects
Status: Done
Development

No branches or pull requests

3 participants