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()
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
print('Close the connection')
writer.close()
+ await writer.wait_closed()
asyncio.run(tcp_echo_client('Hello World!'))
print("Close the connection")
writer.close()
+ await writer.wait_closed()
async def main():
server = await asyncio.start_server(
# Ignore the body, close the socket
writer.close()
+ await writer.wait_closed()
url = sys.argv[1]
asyncio.run(print_http_headers(url))
# Got data, we are done: close the socket
print("Received:", data.decode())
writer.close()
+ await writer.wait_closed()
# Close the second socket
wsock.close()