This repository was archived by the owner on Nov 23, 2017. It is now read-only.

Description
Linux Ubuntu 16.04, Python 3.5, standard asyncio library.
#!/usr/bin/env python3.5
import asyncio
import os
async def test_read_arch(rs):
while True:
d = await rs.read(65536)
if not d:
break
async def test_write_arch(ws):
b = b'x' * (1024 * 1024)
for i in range(30):
ws.write(b)
# await ws.drain() # <----------------- uncomment to speed program for 10 times (!)
await ws.drain() # ensure everything is really written before closing.
ws.close()
async def connect_write_pipe(file):
loop = asyncio.get_event_loop()
transport, protocol = await loop.connect_write_pipe(asyncio.streams.FlowControlMixin, file)
stream_writer = asyncio.StreamWriter(transport, protocol, None, loop)
return stream_writer, transport
async def connect_read_pipe(file):
loop = asyncio.get_event_loop()
stream_reader = asyncio.StreamReader()
transport, protocol = await loop.connect_read_pipe(lambda: asyncio.StreamReaderProtocol(stream_reader), file)
return stream_reader, transport
async def amain():
(r, w) = os.pipe()
stream_reader, rtransport = await connect_read_pipe(open(r, 'rb'))
stream_writer, wtransport = await connect_write_pipe(open(w, 'wb'))
await asyncio.gather(
test_write_arch(stream_writer),
test_read_arch(stream_reader),
)
wtransport.close()
rtransport.close()
def main():
loop = asyncio.get_event_loop()
loop.run_until_complete(amain())
if __name__ == '__main__':
main()