Andrew Svetlov <[email protected]> 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 <[email protected]>
<https://bugs.python.org/issue46568>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com