Python asyncio: reader callback and coroutine communication
问题 I am trying to implement a simple idea of passing a data from stdin to a coroutine: import asyncio import sys event = asyncio.Event() def handle_stdin(): data = sys.stdin.readline() event.data = data # NOTE: data assigned to the event object event.set() @asyncio.coroutine def tick(): while 1: print('Tick') yield from asyncio.sleep(1) if event.is_set(): data = event.data # NOTE: data read from the event object print('Data received: {}'.format(data)) event.clear() def main(): loop = asyncio.get