diff options
author | 0qdk4o <rui0hu@gmail.com> | 2018-07-01 08:16:11 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-01 08:16:11 +0800 |
commit | f42f58745bedd2c6c164d216f6ece21273be418c (patch) | |
tree | 5f89e4185face4e07bb0745e3a7d566e67a8d285 | |
parent | df275d351f9887fba2774e2e1aa79ff1e5a24bd1 (diff) | |
download | websocket-client-f42f58745bedd2c6c164d216f6ece21273be418c.tar.gz |
reset WebsocketApp.sock
consider the following snap
```python
def ws_on_message(ws, message):
msg = json.loads(message)
if msg.get("restart"):
ws.close()
wsapp = websocket.WebSocketApp(url, on_message=ws_on_message, ...)
while True:
wsapp.run_forever()
```
expect restart the connection after receiving restart signal from server.
but we will receive exception `WebSocketException("socket is already opened")` because the method `ws.close()` only close `ws.sock.sock.close()` and reset `ws.sock.sock = None` underlying network socket. noting to do with the ws.sock, it will remeber the previous instance that already invalid now.
-rw-r--r-- | websocket/_app.py | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/websocket/_app.py b/websocket/_app.py index ecdc916..f218576 100644 --- a/websocket/_app.py +++ b/websocket/_app.py @@ -159,6 +159,7 @@ class WebSocketApp(object): self.keep_running = False if self.sock: self.sock.close(**kwargs) + self.sock = None def _send_ping(self, interval, event): while not event.wait(interval): |