https://github.com/python/cpython/commit/ab8c7372fdf9997ed5562a7506bd34af9e17f8c5
commit: ab8c7372fdf9997ed5562a7506bd34af9e17f8c5
branch: main
author: Kumar Aditya <[email protected]>
committer: kumaraditya303 <[email protected]>
date: 2026-08-03T18:07:01Z
summary:
gh-75279: Document that asyncio StreamWriter.drain() may not yield to the event
loop (#155132)
files:
M Doc/library/asyncio-stream.rst
diff --git a/Doc/library/asyncio-stream.rst b/Doc/library/asyncio-stream.rst
index 4092f440f66ad3..885d463c0fca89 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:
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]