Hi,

2014-02-12 10:01 GMT+01:00 Nathan Hoad <[email protected]>:
> Hello,
>
> I was wondering if anyone had tried doing asynchronous interaction with
> stdio, and if so, had they had any success?

Tulip now has multiple examples showing how to interact with stdin and stdout:
- examples/child_process.py (low-level API, as you did)
- examples/shell.py
- examples/subprocess_shell.py

> I had to make some small changes to _UnixWritePipeTransport and
> _UnixReadPipeTransport to check for stat.S_ISCHR (supplementary to S_ISFIFO
> and S_ISSOCK calls).

It looks like you are using an old version, please try the latest
version (0.3.1).

> After I did this, I was able to read from stdin and
> write to stdout separately, but if I mix the two in a given process, then
> writing to stdout breaks. I've traced this down to a
> _UnixWritePipeTransport._read_ready call, indicating the pipe was closed on
> the other end, which I'm inclined to think is not true.

It's hard to tell you what is the problem. First, what is the program
you are running (the one which reads stdin and writes stdout)?

>>     _set_nonblocking(stdin.fileno())
>>     _set_nonblocking(stdout.fileno())
>>     ...
>>     yield from EVENT_LOOP.connect_read_pipe(lambda: reader_protocol,
>> stdin)
>>     transport, protocol = yield from EVENT_LOOP.connect_write_pipe(Stdout,
>> stdout)

I don't think that _set_nonblocking() is needed. It's done by
connect_read/write_pipe() if I remember correctly. Where does
_set_nonblocking() come from? asyncio.unix_events? If yes, please
don't use private methods.

>>     writer = StreamWriter(transport, protocol, reader, EVENT_LOOP)

Here you connect stdin to stdout with the reader parameter. In the
latest version you can pass None for the reader. But it should not be
an issue.

If you would like to make sure that all data are written, you may add:
yield from writer.drain()

Victor

Reply via email to