Skip to content

Commit 83dbc72

Browse files
VietThaniritkatriel
authored andcommitted
gh-100920: Update documentation for asyncio.StreamWriter.wait_closed (#101514)
1 parent 811ff97 commit 83dbc72

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()
@@ -372,7 +373,8 @@ StreamWriter
372373
Wait until the stream is closed.
373374

374375
Should be called after :meth:`close` to wait until the underlying
375-
connection is closed.
376+
connection is closed, ensuring that all data has been flushed
377+
before e.g. exiting the program.
376378

377379
.. versionadded:: 3.7
378380

@@ -402,6 +404,7 @@ TCP echo client using the :func:`asyncio.open_connection` function::
402404

403405
print('Close the connection')
404406
writer.close()
407+
await writer.wait_closed()
405408

406409
asyncio.run(tcp_echo_client('Hello World!'))
407410

@@ -434,6 +437,7 @@ TCP echo server using the :func:`asyncio.start_server` function::
434437

435438
print("Close the connection")
436439
writer.close()
440+
await writer.wait_closed()
437441

438442
async def main():
439443
server = await asyncio.start_server(
@@ -490,6 +494,7 @@ Simple example querying HTTP headers of the URL passed on the command line::
490494

491495
# Ignore the body, close the socket
492496
writer.close()
497+
await writer.wait_closed()
493498

494499
url = sys.argv[1]
495500
asyncio.run(print_http_headers(url))
@@ -535,6 +540,7 @@ Coroutine waiting until a socket receives data using the
535540
# Got data, we are done: close the socket
536541
print("Received:", data.decode())
537542
writer.close()
543+
await writer.wait_closed()
538544

539545
# Close the second socket
540546
wsock.close()

0 commit comments

Comments
 (0)