Hi everyone,

StreamWriter.drain cannot be called from different tasks (asyncio tasks 
that is)
at the same time. It raises an assertion error. I added a script that shows 
this problem.

What I am doing is the following: several tasks in my program are generating
big amounts of data to be shipped out on a StreamWriter. This can easily
overload the receiver of all that data. This is why every task, after 
calling
writer.write also calls "yield from writer.drain()". Unfortunately, while 
draining
another task may write to the same stream writer, also wants to call drain.
This raises an AssertionError.

The problem apparently lies in FlowControlMixin._drain_helper, which assumes
that only one task may wait for a stream to be drained.

(Btw, I am using python 3.4.3)

Greetings

Martin

problem showing script follows:

from asyncio import (async, coroutine, start_server, get_event_loop,
    open_connection, sleep)

@coroutine
def callback(reader, writer):
    yield from sleep(2)

@coroutine
def write(writer):
    writer.write((" " * 100000000).encode("ascii"))
    yield from writer.drain()
    yield from sleep(1)

@coroutine
def test():
    reader, writer = yield from open_connection("localhost", 43522)
    async(write(writer))
    async(write(writer))

async(start_server(callback, port=43522))
get_event_loop().run_until_complete(test())

Reply via email to