[issue46568] non awaited coroutines on a IsolatedAsyncioTestCase results on a RuntimeWarning

Andrew Svetlov report at bugs.python.org
Sat Jan 29 04:38:33 EST 2022


Andrew Svetlov <andrew.svetlov at gmail.com> added the comment:

Your version works but can be simplified.

Just use

    await writer.drain()  
    writer.write(data)

without grabbing the drainer early.
The purpose of the .drain() method is to write pausing if the write buffer side is greater than the high watermark. 
The 'await writer.drain()' waits until the buffer size became less than low watermark. It prevents uncontrollable write buffer growth if a peer cannot accept TCP message as fast as `writer.write()` sends them.
The .drain() call has no hidden process under the hood, there is no need to get write_drain reference as early as possible. It is just 'waiting for a flag'.
Also, there is no need for `await write_drain` at the end: asyncio transport sends all data from the internal write buffer before closing (and doesn't do it on 'transport.abort()').

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46568>
_______________________________________


More information about the Python-bugs-list mailing list