diff --git a/src/simple_websocket/ws.py b/src/simple_websocket/ws.py index b57f754..25d36f9 100644 --- a/src/simple_websocket/ws.py +++ b/src/simple_websocket/ws.py @@ -132,7 +132,10 @@ def _thread(self): if self.ping_interval: next_ping = time() + self.ping_interval sel = self.selector_class() - sel.register(self.sock, selectors.EVENT_READ, True) + try: + sel.register(self.sock, selectors.EVENT_READ, True) + except ValueError: # pragma: no cover + self.connected = False while self.connected: try: @@ -154,7 +157,8 @@ def _thread(self): raise OSError() self.ws.receive_data(in_data) self.connected = self._handle_events() - except (OSError, ConnectionResetError): # pragma: no cover + except (OSError, ConnectionResetError, + LocalProtocolError): # pragma: no cover self.connected = False self.event.set() break