Skip to content

[3.10] gh-100920: Update documentation for asyncio.StreamWriter.wait_closed (GH-101514) #101533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Doc/library/asyncio-stream.rst
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,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()
Expand Down Expand Up @@ -332,7 +333,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

Expand Down Expand Up @@ -361,6 +363,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!'))

Expand Down Expand Up @@ -393,6 +396,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(
Expand Down Expand Up @@ -449,6 +453,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))
Expand Down Expand Up @@ -494,6 +499,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()
Expand Down