File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -485,7 +485,15 @@ async def _signal_exit(self) -> None:
485485 self .logger .verbose ("closing socket..." )
486486 if self ._socket is not None :
487487 self .logger .verbose ("send CloseStream..." )
488- await self ._socket .send (json .dumps ({"type" : "CloseStream" }))
488+ try :
489+ # if the socket connection is closed, the following line might throw an error
490+ await self ._socket .send (json .dumps ({"type" : "CloseStream" }))
491+ except websockets .exceptions .ConnectionClosedOK as e :
492+ self .logger .notice (f"_signal_exit - connection closed: { e .code } " )
493+ except websockets .exceptions .WebSocketException as e :
494+ self .logger .error (f"_signal_exit - WebSocketException: { str (e )} " )
495+ except Exception as e :
496+ self .logger .error (f"_signal_exit - Exception: { str (e )} " )
489497
490498 await asyncio .sleep (0.5 )
491499
Original file line number Diff line number Diff line change @@ -473,7 +473,15 @@ def _signal_exit(self) -> None:
473473 self .logger .notice ("closing socket..." )
474474 if self ._socket is not None :
475475 self .logger .notice ("sending CloseStream..." )
476- self .send (json .dumps ({"type" : "CloseStream" }))
476+ try :
477+ # if the socket connection is closed, the following line might throw an error
478+ self ._socket .send (json .dumps ({"type" : "CloseStream" }))
479+ except websockets .exceptions .ConnectionClosedOK as e :
480+ self .logger .notice (f"_signal_exit - connection closed: { e .code } " )
481+ except websockets .exceptions .WebSocketException as e :
482+ self .logger .error (f"_signal_exit - WebSocketException: { str (e )} " )
483+ except Exception as e :
484+ self .logger .error (f"_signal_exit - Exception: { str (e )} " )
477485
478486 time .sleep (0.5 )
479487
You can’t perform that action at this time.
0 commit comments