[Python-ideas] Adding a subprocess.CompletedProcess class
barry at python.org
Wed Jan 28 17:06:16 CET 2015
On Jan 28, 2015, at 07:34 AM, Gregory P. Smith wrote:
>On Tue Jan 27 2015 at 4:44:32 PM Thomas Kluyver
><thomas at kluyver.me.uk> wrote:
>> 1. Add a CompletedProcess class:
>> * Attributes stdout and stderr are bytes if the relevant stream was piped,
>> None otherwise, like the return value of Popen.communicate()
Note that in Python 3, if universal_newlines=True is given, the output will be
a str, not bytes. (The input is also switched from bytes to str, but that
seems less common, at least in my use cases.) You'll probably build the new
APIs on the existing ones, so I don't expect that to change. I just wanted to
point that out.
>> * Attribute returncode is the exit status
>> * ? Attribute cmd is the list of arguments the process ran with (not sure
>> if this should be there or not)
>> * Method cp.check_returncode() raises CalledProcessError if returncode !=
>> 0, inspired by requests' Response.raise_for_status()
>> 2. Add a run() function - like call/check_call/check_output, but returns a
>> CompletedProcess instance
>I like #1 and #2 here.
>3. Deprecate call/check_call/check_output, but leave them around
>> indefinitely, since lots of existing code relies on them.
>We need to keep those. They are too widely used and are the long term
>stable API for 2.7. They are useful for many simple cases which they were
Agreed that this seems like a nice improvement, but that we need to keep the
old APIs around probably forever.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 819 bytes
Desc: OpenPGP digital signature
More information about the Python-ideas