@@ -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()
@@ -372,7 +373,8 @@ StreamWriter
372
373
Wait until the stream is closed.
373
374
374
375
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.
376
378
377
379
.. versionadded :: 3.7
378
380
@@ -402,6 +404,7 @@ TCP echo client using the :func:`asyncio.open_connection` function::
402
404
403
405
print('Close the connection')
404
406
writer.close()
407
+ await writer.wait_closed()
405
408
406
409
asyncio.run(tcp_echo_client('Hello World!'))
407
410
@@ -434,6 +437,7 @@ TCP echo server using the :func:`asyncio.start_server` function::
434
437
435
438
print("Close the connection")
436
439
writer.close()
440
+ await writer.wait_closed()
437
441
438
442
async def main():
439
443
server = await asyncio.start_server(
@@ -490,6 +494,7 @@ Simple example querying HTTP headers of the URL passed on the command line::
490
494
491
495
# Ignore the body, close the socket
492
496
writer.close()
497
+ await writer.wait_closed()
493
498
494
499
url = sys.argv[1]
495
500
asyncio.run(print_http_headers(url))
@@ -535,6 +540,7 @@ Coroutine waiting until a socket receives data using the
535
540
# Got data, we are done: close the socket
536
541
print("Received:", data.decode())
537
542
writer.close()
543
+ await writer.wait_closed()
538
544
539
545
# Close the second socket
540
546
wsock.close()
0 commit comments