Aymeric Augustin added the comment:

drain() returns when the write buffer reaches the low water mark, not when it's 
empty, so you don't have a guarantee that your bytes were written to the socket.

https://github.com/python/cpython/blob/6f0eb93183519024cb360162bdd81b9faec97ba6/Lib/asyncio/protocols.py#L36-L40

The low water mark defaults to 64kB and the high water mark to 256kB.

https://github.com/python/cpython/blob/6f0eb93183519024cb360162bdd81b9faec97ba6/Lib/asyncio/transports.py#L290

With websockets, the recommended way to ensure your message was received is:

yield from ws.send(...)
yield from ws.ping()

Given that TCP guarantees ordering, the ping response can only be received 
after the previous message was fully sent and received.

Of course the ping can fail even though the message was received, that's the 
classical at-most-once vs. at-least-once question.

The technique you suggest requires setting the low and high water marks to 0. 
I'm not sure this is the best way to achieve your goals, since you still don't 
control the OS buffers.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29930>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to