2014/1/23 Glyph <[email protected]>:
> On Jan 22, 2014, at 7:33 AM, Guido van Rossum <[email protected]> wrote:
>> The solution is simple: write that logic as a separate method marked
>> with @coroutine, and fire it off in data_received() using async() (==
>> Task(), in this case). E.g.
>
> Wouldn't that process each subsequent TCP segment in a parallel coroutine,
> thereby with multiple segments of data stomping on each other if they're
> yielding during processing?

Hum, I tried to write something to explain that in asyncio documentation:

+Coroutines and protocols
+------------------------
+
+Coroutines can be scheduled in a protocol method using :func:`async`, but there
+is not guarantee on the execution order. Protocols are not aware of coroutines
+created in protocol methods and so will not wait for them.
+
+To have a reliable execution order, use :ref:`stream objects <streams>` in a
+coroutine with ``yield from``. For example, the :meth:`StreamWriter.drain`
+coroutine can be used to wait until the write buffer is flushed.

Victor

Reply via email to