For those following along at home, the discussion moved to Tulip issue 115:
http://code.google.com/p/tulip/issues/detail?id=115



On Sat, Jan 25, 2014 at 7:24 PM, Victor Stinner <[email protected]>wrote:

> 2014-01-24 Victor Stinner <[email protected]>:
> > I will try to hack asyncio to see how StreamWriter can be implemented
> for stdin.
>
> I created a subproces-stream branch (oops, typo!) in Tulip repository.
> It's a work in progress, but it works :-) Attached patch are the
> differences with the default branch.
>
> I tried to limit changes on existing code:
>
> - add SubprocessProtocol.pip_connection_made(): needed to retrieve the
> writer for stdin
> - add two attributes to SubprocessProtocol: read_pipe_protocol,
> write_pipe_protocol => factories to build protocols for stdout/stderr
> and stdin
>
> I added new classes in asyncio/subprocess_stream.py.
>
> The syntax is more what I expect from asyncio: asynchronous read and
> write (instead of callbacks). You can also wait for the completion of
> the write (drain: wait until the write buffer is flushed) and wait
> until the process exited (wait).
>
> Example:
> ---
> @asyncio.coroutine
> def cat(loop):
>     transport, protocol = yield from
> loop.subprocess_shell(asyncio.SubprocessStreamProtocol, "cat")
>
>     protocol.stdin.write(b"Hello World!")
>     yield from protocol.stdin.drain()
>     protocol.stdin.close()
>
>     print((yield from protocol.stdout.read()).decode('ascii'))
>
>     returncode = yield from proc.wait()
>     print("exit code: %s" % returncode)
> ---
>
> See examples/subprocess_stream.py for a more complete example.
>
> I didn't test on Windows yet.
>
> I prefer to add attributes to SubprocessProtocol instead of passing
> new (keyword) parameters to subprocess_exec/subprocess_shell. The pipe
> protocols are related the subprocess protocol: see
> SubprocessStreamProtocol.pipe_connection_madeSubprocess().
>
> Victor
>



-- 
--Guido van Rossum (python.org/~guido)

Reply via email to