3 ms·
I had so much trouble getting the python tcp client to work like I wanted it to. Then I tried my hand on the async tcp client and was pleasantly surprised how s
by nurettin 6y ago
I had so much trouble getting the python tcp client to work like I wanted it to. Then I tried my hand on the async tcp client and was pleasantly surprised how simple it was.
reader, writer = await asyncio.wait_for(asyncio.open_connection(), connect_timeout)
line = ""
while True:
line = await asyncio.wait_for(reader.readline(), read_timeout)
if line == b"":
break
yield line
- andrewstuart 6y agoI've written a bunch of things that were really well suited to async Python including an mpjeg server, a queueing server and a process management server that monitors the stdout and stderr of various processes and reads them in real time and acts upon the messages it reads. Each one of those applications was made possible comprehensible and even easy by async Python.
- nurettin 6y agoI made a python clone of multitail in just under a day thanks to being able to read multiple files simultaneously with async. It really is overpowered.
- euiq 6y agoThe current stream interface is still somewhat awkward. Apart from the question whether the reader and writer really need to separate objects, there's also the problem that the write and close methods are synchronous—in order to use them correctly, it's necessary to throw in asynchronous calls to drain and wait_closed. There was a plan to fix this in Python 3.8, but that never went anywhere.