-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
asyncio subprocess stdin/out/err can be filehandles, but this is undocumented #105857
Comments
I'm not sure if this is just a lack of documentation or whether it is intentional, to discourage using raw file descriptors? There might be some problems in edge cases (e.g. sockets on Windows). If you have a simple example of how you used this successfully that would also help. |
example:
(the actual code I'm using is a fair bit more complex and takes care of closing handles etc). I think it's just an omission, not intentional. The asyncio subprocess functions are mostly just wrappers for Popen, which is the thing handling the file handles; and it's handled in both unix and windows variants. The non-asyncio subprocess documents that file descriptors are ok: https://docs.python.org/3/library/subprocess.html#frequently-used-arguments "stdin, stdout and stderr specify the executed program’s standard input, standard output and standard error file handles, respectively. Valid values are PIPE, DEVNULL, an existing file descriptor (a positive integer), an existing file object with a valid file descriptor, and None." In the asyncio subprocess implementation, cpython/Lib/asyncio/unix_events.py Lines 821 to 823 in 1858db7
Popen calls _get_handles: Line 992 in 1858db7
which handles the int filehandles case: https://github.com/python/cpython/blob/main/Lib/subprocess.py#L1704-L1705
|
Okay, makes sense. Would you like to submit a doc PR? (I wouldn't mind if the docs were refactored to avoid repeating everything three times, though maybe there are differences that make this tricky, so up to you.) |
I have added a pr here, extending the docs. #107986 |
…le handles (#107986) stdin/out can be filehandles -> add to docs.
… be file handles (pythonGH-107986) stdin/out can be filehandles -> add to docs. (cherry picked from commit 13966da) Co-authored-by: Hadházy Tamás <[email protected]>
…n be file handles (GH-107986) (#108332) (cherry picked from commit 13966da) Co-authored-by: Hadházy Tamás <[email protected]>
Documentation
I was trying to write some asyncio subprocess code to pipe from one process to another, struggled until I found examples with os.pipe(). But going back to the docs I was confused because passing a filehandle isn't mentioned as an option. Looking at the underlying code, I see it definitely is supported, there's a check for the parameter being an integer and the handle is used directly.
The incorrect documentation is here
cpython/Doc/library/asyncio-eventloop.rst
Lines 1439 to 1469 in 101d5ec
So instead of
I'd suggest:
(and similarly for stdout and stderr)
Linked PRs
The text was updated successfully, but these errors were encountered: