Created
April 29, 2018 09:45
-
-
Save tveastman/fa544fc13cb1d32d03d3c02b1d49f6e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
import asyncio | |
async def get_stream_reader(loop, stream): | |
reader = asyncio.StreamReader(loop=loop) | |
reader_protocol = asyncio.StreamReaderProtocol(reader) | |
await loop.connect_read_pipe(lambda: reader_protocol, stream) | |
return reader | |
async def main(loop): | |
reader = await get_stream_reader(loop, sys.stdin) | |
while True: | |
line = await reader.readline() | |
if not line: | |
break | |
print('read {} from stdin'.format(repr(line))) | |
if __name__ == '__main__': | |
loop = asyncio.get_event_loop() | |
loop.run_until_complete(main(loop)) | |
loop.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment