Skip to content

Commit 02befc8

Browse files
[3.13] gh-75279: Document that asyncio StreamWriter.drain() may not yield to the event loop (GH-155132) (#155136)
gh-75279: Document that asyncio StreamWriter.drain() may not yield to the event loop (GH-155132) (cherry picked from commit ab8c737) Co-authored-by: Kumar Aditya <kumaraditya@python.org>
1 parent 8e39962 commit 02befc8

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

Doc/library/asyncio-stream.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,16 @@ StreamWriter
382382
be resumed. When there is nothing to wait for, the :meth:`drain`
383383
returns immediately.
384384

385+
.. note::
386+
387+
When the write buffer is below the high watermark,
388+
:meth:`drain` returns immediately without yielding to
389+
the event loop. As a result, code which repeatedly calls
390+
``write()`` followed by ``await drain()`` may prevent other
391+
tasks from running. To prevent blocking behavior, yield
392+
to the event loop explicitly with ``await asyncio.sleep(0)``
393+
(see :func:`asyncio.sleep`).
394+
385395
.. method:: start_tls(sslcontext, *, server_hostname=None, \
386396
ssl_handshake_timeout=None, ssl_shutdown_timeout=None)
387397
:async:

0 commit comments

Comments
 (0)