import asyncio import sys @asyncio.coroutine def test_pause_reading(): chunk_size = 100 code = '\n'.join(( 'import sys', 'import time', 'buffer = "x" * %s' % chunk_size, 'for line in range(4):', ' sys.stdout.write(buffer)', ' sys.stdout.flush()', ' time.sleep(0.250)', )) proc = yield from asyncio.create_subprocess_exec( sys.executable, '-c', code, stdout=asyncio.subprocess.PIPE, limit=chunk_size // 2 - 1) stdout, stderr = yield from proc.communicate() loop = asyncio.get_event_loop() queue = asyncio.Queue() loop.run_until_complete(test_pause_reading()) loop.close()