2014/1/22 Phil Schaf <[email protected]>:
> while True:
> msg = yield from dataqueue.read()
> yield from self.handle_msg(msg.data, writer)
Using this code, no data can be read while handle_msg() is running.
IMO you should split the two parts in two tasks. Something like that:
---
@coroutine
def reader(parser, queue, worker_task):
try:
while True:
msg = yield from parser.read()
if msg == 'cancel':
break
queue.put(msg)
finally:
worker_task.cancel()
@coroutine
def worker(queue):
while True:
msg = yield from queue.get()
yield from handle_msg(msg)
def create_client(parser):
queue = asyncio.queues.Queue()
worker_task = async(worker(queue))
reader_task = async(reader(dataqueue, queue, worker_task))
# worker and reader are running in parallel
# worker_task can be cancelled, it will cancel the worker() in cascade
return worker_task
---
Victor