From: Kumar Aditya Date: Mon, 3 Aug 2026 18:07:01 +0000 (+0530) Subject: gh-75279: Document that asyncio StreamWriter.drain() may not yield to the event loop... X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ab8c7372fdf9997ed5562a7506bd34af9e17f8c5;p=thirdparty%2FPython%2Fcpython.git gh-75279: Document that asyncio StreamWriter.drain() may not yield to the event loop (#155132) --- diff --git a/Doc/library/asyncio-stream.rst b/Doc/library/asyncio-stream.rst index 4092f440f66a..885d463c0fca 100644 --- a/Doc/library/asyncio-stream.rst +++ b/Doc/library/asyncio-stream.rst @@ -389,6 +389,16 @@ StreamWriter be resumed. When there is nothing to wait for, the :meth:`drain` returns immediately. + .. note:: + + When the write buffer is below the high watermark, + :meth:`drain` returns immediately without yielding to + the event loop. As a result, code which repeatedly calls + ``write()`` followed by ``await drain()`` may prevent other + tasks from running. To prevent blocking behavior, yield + to the event loop explicitly with ``await asyncio.sleep(0)`` + (see :func:`asyncio.sleep`). + .. method:: start_tls(sslcontext, *, server_hostname=None, \ ssl_handshake_timeout=None, ssl_shutdown_timeout=None) :async: