Skip to content

Commit 383bcef

Browse files
committed
Catching asyncio.CancelledError instead of KeyboardInterrupt and EOFError. Asyncio will catch these errors outside of the task and raise the CancelledError to cancel the task. This makes sure that the websocket client is properly disconnected if the user press control-C or control-D.
1 parent d7dafcc commit 383bcef

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/websockets/cli.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import argparse
44
import asyncio
5+
from asyncio import CancelledError
56
import os
67
import sys
78
from typing import Generator
@@ -123,7 +124,7 @@ async def interactive_client(uri: str) -> None:
123124
[incoming, outgoing],
124125
return_when=asyncio.FIRST_COMPLETED,
125126
)
126-
except (KeyboardInterrupt, EOFError): # ^C, ^D # pragma: no cover
127+
except CancelledError: # ^C, ^D # pragma: no cover
127128
pass
128129
finally:
129130
incoming.cancel()

0 commit comments

Comments
 (0)