]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-100920: Update documentation for `asyncio.StreamWriter.wait_closed` (#101514)
authorViet Than <thanhoangviet@gmail.com>
Fri, 3 Feb 2023 07:18:39 +0000 (02:18 -0500)
committerGitHub <noreply@github.com>
Fri, 3 Feb 2023 07:18:39 +0000 (12:48 +0530)
Doc/library/asyncio-stream.rst

index 533bdec8e03993b770c6623f5938cd9975113b79..3b3c68ab6ef6258d40c4aae4c4706d79d548e5f3 100644 (file)
@@ -295,7 +295,8 @@ StreamWriter
 
       The method closes the stream and the underlying socket.
 
-      The method should be used along with the ``wait_closed()`` method::
+      The method should be used, though not mandatory,
+      along with the ``wait_closed()`` method::
 
          stream.close()
          await stream.wait_closed()
@@ -372,7 +373,8 @@ StreamWriter
       Wait until the stream is closed.
 
       Should be called after :meth:`close` to wait until the underlying
-      connection is closed.
+      connection is closed, ensuring that all data has been flushed
+      before e.g. exiting the program.
 
       .. versionadded:: 3.7
 
@@ -402,6 +404,7 @@ TCP echo client using the :func:`asyncio.open_connection` function::
 
         print('Close the connection')
         writer.close()
+        await writer.wait_closed()
 
     asyncio.run(tcp_echo_client('Hello World!'))
 
@@ -434,6 +437,7 @@ TCP echo server using the :func:`asyncio.start_server` function::
 
         print("Close the connection")
         writer.close()
+        await writer.wait_closed()
 
     async def main():
         server = await asyncio.start_server(
@@ -490,6 +494,7 @@ Simple example querying HTTP headers of the URL passed on the command line::
 
         # Ignore the body, close the socket
         writer.close()
+        await writer.wait_closed()
 
     url = sys.argv[1]
     asyncio.run(print_http_headers(url))
@@ -535,6 +540,7 @@ Coroutine waiting until a socket receives data using the
         # Got data, we are done: close the socket
         print("Received:", data.decode())
         writer.close()
+        await writer.wait_closed()
 
         # Close the second socket
         wsock.close()