Completely flushing a StreamWriter

Hi there –

The docs for asyncio.StreamWriter suggest that the drain method only drains the writer so far as it is “safe to resume writing”, and that what this method guarantees is that “…the buffer is drained down to the low watermark”.

My question is: How do I ensure that the buffer is FULLY drained? I know that Python 3.7 added wait_closed, but I don’t intend to close the stream yet, only ensure that we’ve reached a quiescent point before continuing.

I suppose I might be able to use WriteTransport.set_write_buffer_limits() and temporarily force the buffer to 0, call drain, and then restore the prior buffer limits?

–John Snow (QEMU project Python maintainer)