@@ -295,7 +295,8 @@ StreamWriter
295
295
296
296
The method closes the stream and the underlying socket.
297
297
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::
299
300
300
301
stream.close()
301
302
await stream.wait_closed()
@@ -364,7 +365,8 @@ StreamWriter
364
365
Wait until the stream is closed.
365
366
366
367
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.
368
370
369
371
.. versionadded :: 3.7
370
372
@@ -394,6 +396,7 @@ TCP echo client using the :func:`asyncio.open_connection` function::
394
396
395
397
print('Close the connection')
396
398
writer.close()
399
+ await writer.wait_closed()
397
400
398
401
asyncio.run(tcp_echo_client('Hello World!'))
399
402
@@ -426,6 +429,7 @@ TCP echo server using the :func:`asyncio.start_server` function::
426
429
427
430
print("Close the connection")
428
431
writer.close()
432
+ await writer.wait_closed()
429
433
430
434
async def main():
431
435
server = await asyncio.start_server(
@@ -482,6 +486,7 @@ Simple example querying HTTP headers of the URL passed on the command line::
482
486
483
487
# Ignore the body, close the socket
484
488
writer.close()
489
+ await writer.wait_closed()
485
490
486
491
url = sys.argv[1]
487
492
asyncio.run(print_http_headers(url))
@@ -527,6 +532,7 @@ Coroutine waiting until a socket receives data using the
527
532
# Got data, we are done: close the socket
528
533
print("Received:", data.decode())
529
534
writer.close()
535
+ await writer.wait_closed()
530
536
531
537
# Close the second socket
532
538
wsock.close()
0 commit comments