@@ -281,7 +281,8 @@ StreamWriter
281
281
282
282
The method closes the stream and the underlying socket.
283
283
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::
285
286
286
287
stream.close()
287
288
await stream.wait_closed()
@@ -332,7 +333,8 @@ StreamWriter
332
333
Wait until the stream is closed.
333
334
334
335
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.
336
338
337
339
.. versionadded :: 3.7
338
340
@@ -361,6 +363,7 @@ TCP echo client using the :func:`asyncio.open_connection` function::
361
363
362
364
print('Close the connection')
363
365
writer.close()
366
+ await writer.wait_closed()
364
367
365
368
asyncio.run(tcp_echo_client('Hello World!'))
366
369
@@ -393,6 +396,7 @@ TCP echo server using the :func:`asyncio.start_server` function::
393
396
394
397
print("Close the connection")
395
398
writer.close()
399
+ await writer.wait_closed()
396
400
397
401
async def main():
398
402
server = await asyncio.start_server(
@@ -449,6 +453,7 @@ Simple example querying HTTP headers of the URL passed on the command line::
449
453
450
454
# Ignore the body, close the socket
451
455
writer.close()
456
+ await writer.wait_closed()
452
457
453
458
url = sys.argv[1]
454
459
asyncio.run(print_http_headers(url))
@@ -494,6 +499,7 @@ Coroutine waiting until a socket receives data using the
494
499
# Got data, we are done: close the socket
495
500
print("Received:", data.decode())
496
501
writer.close()
502
+ await writer.wait_closed()
497
503
498
504
# Close the second socket
499
505
wsock.close()
0 commit comments