I somehow suspect that in order to help Phil debug his code we need to
see all of it, not just the few lines he quoted. There are many
details in the way you hook things up that could cause the described
effect. (Phil, do you still need help?)

On Fri, Jan 24, 2014 at 9:06 AM, Victor Stinner
<[email protected]> wrote:
> 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



-- 
--Guido van Rossum (python.org/~guido)

Reply via email to