Explain an assert when waiting on a asyncio stream drain

If a task is waiting on a stream to drain and another task tries to
this assertion will fail. It wasn't clear at first glance why the
assertion failed, but I hope with this message it will be.
This commit is contained in:
pgjones 2020-03-31 12:29:06 +01:00
parent c49016e67c
commit 8823ed8b88
1 changed files with 3 additions and 1 deletions

View File

@ -191,7 +191,9 @@ class FlowControlMixin(protocols.Protocol):
if not self._paused:
return
waiter = self._drain_waiter
assert waiter is None or waiter.cancelled()
assert waiter is None or waiter.cancelled(), (
'Another task is waiting for this stream to drain'
)
waiter = self._loop.create_future()
self._drain_waiter = waiter
await waiter