File tree 1 file changed +12
-2
lines changed
1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -121,9 +121,15 @@ async def interactive_client(uri: str) -> None:
121
121
try :
122
122
await asyncio .wait (
123
123
[incoming , outgoing ],
124
+ # Clean up and exit when the server closes the connection
125
+ # or the user enters EOT (^D), whichever happens first.
124
126
return_when = asyncio .FIRST_COMPLETED ,
125
127
)
126
- except (KeyboardInterrupt , EOFError ): # ^C, ^D # pragma: no cover
128
+ # asyncio.run() cancels the main task when the user triggers SIGINT (^C).
129
+ # https://docs.python.org/3/library/asyncio-runner.html#handling-keyboard-interruption
130
+ # Clean up and exit without re-raising CancelledError to prevent Python
131
+ # from raising KeyboardInterrupt and displaying a stack track.
132
+ except asyncio .CancelledError : # pragma: no cover
127
133
pass
128
134
finally :
129
135
incoming .cancel ()
@@ -165,4 +171,8 @@ def main(argv: list[str] | None = None) -> None:
165
171
except ImportError : # readline isn't available on all platforms
166
172
pass
167
173
168
- asyncio .run (interactive_client (args .uri ))
174
+ # Remove the try/except block when dropping Python < 3.11.
175
+ try :
176
+ asyncio .run (interactive_client (args .uri ))
177
+ except KeyboardInterrupt : # pragma: no cover
178
+ pass
You can’t perform that action at this time.
0 commit comments