]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-75279: Document that asyncio StreamWriter.drain() may not yield to the event loop...
authorKumar Aditya <kumaraditya@python.org>
Mon, 3 Aug 2026 18:07:01 +0000 (23:37 +0530)
committerGitHub <noreply@github.com>
Mon, 3 Aug 2026 18:07:01 +0000 (18:07 +0000)
Doc/library/asyncio-stream.rst

index 4092f440f66ad3b471861f17ce50ea253f03ab92..885d463c0fca898f8d10804b1e5c44beebbfa8a9 100644 (file)
@@ -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: