[New-bugs-announce] [issue40707] Popen.communicate documentation does not say how to get the return code

Gareth Rees report at bugs.python.org
Thu May 21 03:34:10 EDT 2020


New submission from Gareth Rees <gdr at garethrees.org>:

When using subprocess.Popen.communicate(), it is natural to wonder how to get
the exit code of the subprocess. However, the documentation [1] says:

    Interact with process: Send data to stdin. Read data from stdout and
    stderr, until end-of-file is reached. Wait for process to terminate. The
    optional input argument should be data to be sent to the child process, or
    None, if no data should be sent to the child. If streams were opened in
    text mode, input must be a string. Otherwise, it must be bytes.

    communicate() returns a tuple (stdout_data, stderr_data). The data will be
    strings if streams were opened in text mode; otherwise, bytes.

If you can guess that communicate() might set returncode, then you can find
what you need in the documentation for that attribute [2]:

    The child return code, set by poll() and wait() (and indirectly by
    communicate()).

I suggest that the documentation for communicate() be updated to mention that
it sets the returncode attribute. This would be consistent with poll() and
wait(), which already mention this.

[1]: https://docs.python.org/3/library/subprocess.html#subprocess.Popen.communicate
[2]: https://docs.python.org/3/library/subprocess.html#subprocess.Popen.returncode

----------
assignee: docs at python
components: Documentation
messages: 369502
nosy: docs at python, gdr at garethrees.org
priority: normal
severity: normal
status: open
title: Popen.communicate documentation does not say how to get the return code
type: enhancement
versions: Python 3.10, Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40707>
_______________________________________


More information about the New-bugs-announce mailing list