[issue26848] asyncio.subprocess's communicate() method mishandles empty input bytes

Jack O'Connor report at bugs.python.org
Tue Apr 26 01:25:15 EDT 2016


Jack O'Connor added the comment:

Related: The asyncio communicate() method differs from standard subprocess in how it treats input bytes when stdin is (probably mistakenly) not set to PIPE. Like this:

    proc = await create_subprocess_shell("sleep 5")
    await proc.communicate(b"foo")  # Oops, I forgot stdin=PIPE above!

The standard, non-async version of this example, communicate would ignore the input bytes entirely. But here in the asyncio version, communicate will try to write those bytes to stdin, which is None, and the result is an AttributeError.

Since the user probably only hits this case by mistake, I think raising an exception is preferable. But it would be nice to raise an exception that explicitly said "you've forgotten stdin=PIPE" instead of the unhelpful "'NoneType' object has no attribute 'write'". Maybe it would be worth cleaning this up while we're here?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26848>
_______________________________________


More information about the Python-bugs-list mailing list