Skip to content

Commit 2366c1a

Browse files
gh-100920: Update documentation for asyncio.StreamWriter.wait_closed (GH-101514)
(cherry picked from commit 5c39daf) Co-authored-by: Viet Than <[email protected]>
1 parent bfac5d9 commit 2366c1a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Doc/library/asyncio-stream.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ StreamWriter
295295

296296
The method closes the stream and the underlying socket.
297297

298-
The method should be used along with the ``wait_closed()`` method::
298+
The method should be used, though not mandatory,
299+
along with the ``wait_closed()`` method::
299300

300301
stream.close()
301302
await stream.wait_closed()
@@ -364,7 +365,8 @@ StreamWriter
364365
Wait until the stream is closed.
365366

366367
Should be called after :meth:`close` to wait until the underlying
367-
connection is closed.
368+
connection is closed, ensuring that all data has been flushed
369+
before e.g. exiting the program.
368370

369371
.. versionadded:: 3.7
370372

@@ -394,6 +396,7 @@ TCP echo client using the :func:`asyncio.open_connection` function::
394396

395397
print('Close the connection')
396398
writer.close()
399+
await writer.wait_closed()
397400

398401
asyncio.run(tcp_echo_client('Hello World!'))
399402

@@ -426,6 +429,7 @@ TCP echo server using the :func:`asyncio.start_server` function::
426429

427430
print("Close the connection")
428431
writer.close()
432+
await writer.wait_closed()
429433

430434
async def main():
431435
server = await asyncio.start_server(
@@ -482,6 +486,7 @@ Simple example querying HTTP headers of the URL passed on the command line::
482486

483487
# Ignore the body, close the socket
484488
writer.close()
489+
await writer.wait_closed()
485490

486491
url = sys.argv[1]
487492
asyncio.run(print_http_headers(url))
@@ -527,6 +532,7 @@ Coroutine waiting until a socket receives data using the
527532
# Got data, we are done: close the socket
528533
print("Received:", data.decode())
529534
writer.close()
535+
await writer.wait_closed()
530536

531537
# Close the second socket
532538
wsock.close()

0 commit comments

Comments
 (0)