This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author asvetlov
Recipients asvetlov, bluecarrot, yselivanov
Date 2022-01-29.09:38:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1643449113.95.0.563016514024.issue46568@roundup.psfhosted.org>
In-reply-to
Content
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()').
History
Date User Action Args
2022-01-29 09:38:33asvetlovsetrecipients: + asvetlov, yselivanov, bluecarrot
2022-01-29 09:38:33asvetlovsetmessageid: <1643449113.95.0.563016514024.issue46568@roundup.psfhosted.org>
2022-01-29 09:38:33asvetlovlinkissue46568 messages
2022-01-29 09:38:33asvetlovcreate