Skip to content

Commit 91abba4

Browse files
committed
Create close coroutine only when scheduling it.
Otherwise, this can lead to: RuntimeWarning: coroutine 'Connection.close' was never awaited Fix #1647.
1 parent e57b315 commit 91abba4

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

docs/faq/client.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ You can close the connection.
103103
Here's an example that terminates cleanly when it receives SIGTERM on Unix:
104104

105105
.. literalinclude:: ../../example/faq/shutdown_client.py
106-
:emphasize-lines: 10-12
106+
:emphasize-lines: 10-14
107107

108108
How do I disable TLS/SSL certificate verification?
109109
--------------------------------------------------

example/faq/shutdown_client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ async def client():
99
async with connect("ws://localhost:8765") as websocket:
1010
# Close the connection when receiving SIGTERM.
1111
loop = asyncio.get_running_loop()
12-
loop.add_signal_handler(signal.SIGTERM, loop.create_task, websocket.close())
12+
def close():
13+
return loop.create_task(websocket.close())
14+
loop.add_signal_handler(signal.SIGTERM, close)
1315

1416
# Process messages received on the connection.
1517
async for message in websocket:

0 commit comments

Comments
 (0)