Skip to content

Commit 4c732bc

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 c3dd95a commit 4c732bc

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
@@ -281,7 +281,8 @@ StreamWriter
281281

282282
The method closes the stream and the underlying socket.
283283

284-
The method should be used along with the ``wait_closed()`` method::
284+
The method should be used, though not mandatory,
285+
along with the ``wait_closed()`` method::
285286

286287
stream.close()
287288
await stream.wait_closed()
@@ -332,7 +333,8 @@ StreamWriter
332333
Wait until the stream is closed.
333334

334335
Should be called after :meth:`close` to wait until the underlying
335-
connection is closed.
336+
connection is closed, ensuring that all data has been flushed
337+
before e.g. exiting the program.
336338

337339
.. versionadded:: 3.7
338340

@@ -361,6 +363,7 @@ TCP echo client using the :func:`asyncio.open_connection` function::
361363

362364
print('Close the connection')
363365
writer.close()
366+
await writer.wait_closed()
364367

365368
asyncio.run(tcp_echo_client('Hello World!'))
366369

@@ -393,6 +396,7 @@ TCP echo server using the :func:`asyncio.start_server` function::
393396

394397
print("Close the connection")
395398
writer.close()
399+
await writer.wait_closed()
396400

397401
async def main():
398402
server = await asyncio.start_server(
@@ -449,6 +453,7 @@ Simple example querying HTTP headers of the URL passed on the command line::
449453

450454
# Ignore the body, close the socket
451455
writer.close()
456+
await writer.wait_closed()
452457

453458
url = sys.argv[1]
454459
asyncio.run(print_http_headers(url))
@@ -494,6 +499,7 @@ Coroutine waiting until a socket receives data using the
494499
# Got data, we are done: close the socket
495500
print("Received:", data.decode())
496501
writer.close()
502+
await writer.wait_closed()
497503

498504
# Close the second socket
499505
wsock.close()

0 commit comments

Comments
 (0)