Skip to content

asyncio subprocess stdin/out/err can be filehandles, but this is undocumented #105857

@bewinsnw

Description

@bewinsnw

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

* *stdin* can be any of these:
* a file-like object
* the :const:`subprocess.PIPE` constant (default) which will create a new
pipe and connect it,
* the value ``None`` which will make the subprocess inherit the file
descriptor from this process
* the :const:`subprocess.DEVNULL` constant which indicates that the
special :data:`os.devnull` file will be used
* *stdout* can be any of these:
* a file-like object
* the :const:`subprocess.PIPE` constant (default) which will create a new
pipe and connect it,
* the value ``None`` which will make the subprocess inherit the file
descriptor from this process
* the :const:`subprocess.DEVNULL` constant which indicates that the
special :data:`os.devnull` file will be used
* *stderr* can be any of these:
* a file-like object
* the :const:`subprocess.PIPE` constant (default) which will create a new
pipe and connect it,
* the value ``None`` which will make the subprocess inherit the file
descriptor from this process
* the :const:`subprocess.DEVNULL` constant which indicates that the
special :data:`os.devnull` file will be used
* the :const:`subprocess.STDOUT` constant which will connect the standard
error stream to the process' standard output stream

So instead of

   * *stdin* can be any of these:

     * a file-like object
     * the :const:`subprocess.PIPE` constant (default) which will create a new
       pipe and connect it,...

I'd suggest:

   * *stdin* can be any of these:
  
     * a file-like object
     * an existing file descriptor (a positive integer), for example those created with :meth:`os.pipe()`,
     * the :const:`subprocess.PIPE` constant (default) which will create a new
       pipe and connect it,...

(and similarly for stdout and stderr)

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions