Hi,

It looks like it's not possible to connect the stdout of a subprocess
to the stdin of another subprocess using the API of the
asyncio.subprocess module.

IMO the (subprocess.)Popen objects should be created first, pipes
connected, and then create (asyncio.subprocess.)Process wrapper. Or
maybe a new API is needed.

My test:
---
import asyncio
import asyncio.subprocess

@asyncio.coroutine
def task():
    cat = yield from asyncio.create_subprocess_shell(
                                 'cat /etc/passwd',
                                 stdout=asyncio.subprocess.PIPE)
    stdout = cat._transport.get_pipe_transport(1)
#    yield from asyncio.sleep(1)
    grep = yield from asyncio.create_subprocess_shell(
                                 'grep haypo',
                                 stdin=stdout._fileno,
                                 stdout=asyncio.subprocess.PIPE)
    stdout.close()
    stdout, stderr = yield from grep.communicate()
    print("stdout >>>%r<<<" % stdout)

loop = asyncio.get_event_loop()
loop.run_until_complete(task())
---

This example is a major race condition: if cat produces data before
the pipe is connected to grep stdin, data is lost (not passed to grep,
but written into cat.stdout stream reader).

Victor

Reply via email to