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?

It seems to me that the real solution to do this (IntNReceiver) in the 
coroutine style would be to use StreamReader, and then do something like this:

@coroutine
def read_one_string():
    prefix_length = struct.calcsize(prefix_format)
    prefix = yield from reader.readexactly(prefix_length)
    size = struct.unpack(prefix_format, prefix)[0]
    return (yield from reader.readexactly(size))

If you don't want to use StreamReader, then you'll need to implement something 
like what it does with feed_data, unblocking futures that are waiting for 
data_received to be called:

<https://code.google.com/p/tulip/source/browse/asyncio/streams.py#261>.

-glyph

Reply via email to