diff options
| author | Guido van Rossum <guido@python.org> | 2013-08-08 10:33:20 -0700 |
|---|---|---|
| committer | Guido van Rossum <guido@python.org> | 2013-08-08 10:33:20 -0700 |
| commit | 457ab85f756c50cda06adb9c99a1b8b466d14ccd (patch) | |
| tree | 24d4de8fd76eb6552926326629ccf7c1e38d1e13 /examples/child_process.py | |
| parent | 089d9a4d334cbd59593c7cfc1d5f736f3aa7a901 (diff) | |
| download | trollius-457ab85f756c50cda06adb9c99a1b8b466d14ccd.tar.gz | |
Fix for examples/child_process.py by Gustavo Carneiro <gjcarneiro@gmail.com>.
Diffstat (limited to 'examples/child_process.py')
| -rw-r--r-- | examples/child_process.py | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/examples/child_process.py b/examples/child_process.py index a799fa2..d4a035b 100644 --- a/examples/child_process.py +++ b/examples/child_process.py @@ -27,21 +27,26 @@ else: # Return a write-only transport wrapping a writable pipe # +@tulip.coroutine def connect_write_pipe(file): loop = tulip.get_event_loop() protocol = protocols.Protocol() - return loop._make_write_pipe_transport(file, protocol) + transport, _ = yield from loop.connect_write_pipe(tulip.Protocol, file) + return transport # # Wrap a readable pipe in a stream # +@tulip.coroutine def connect_read_pipe(file): loop = tulip.get_event_loop() stream_reader = streams.StreamReader(loop=loop) - protocol = streams.StreamReaderProtocol(stream_reader) - transport = loop._make_read_pipe_transport(file, protocol) - return stream_reader + def factory(): + return streams.StreamReaderProtocol(stream_reader) + transport, _ = yield from loop.connect_read_pipe(factory, file) + return stream_reader, transport + # # Example @@ -76,9 +81,10 @@ def main(loop): # start subprocess and wrap stdin, stdout, stderr p = Popen([sys.executable, '-c', code], stdin=PIPE, stdout=PIPE, stderr=PIPE) - stdin = connect_write_pipe(p.stdin) - stdout = connect_read_pipe(p.stdout) - stderr = connect_read_pipe(p.stderr) + + stdin = yield from connect_write_pipe(p.stdin) + stdout, stdout_transport = yield from connect_read_pipe(p.stdout) + stderr, stderr_transport = yield from connect_read_pipe(p.stderr) # interact with subprocess name = {stdout:'OUT', stderr:'ERR'} @@ -108,6 +114,8 @@ def main(loop): registered[tulip.Task(stream.readline())] = stream timeout = 0.0 + stdout_transport.close() + stderr_transport.close() if __name__ == '__main__': if sys.platform == 'win32': |
