From 16ebf78e9021368da39362f1540d3b86dbb03db4 Mon Sep 17 00:00:00 2001 From: Shawn Chapla Date: Sat, 1 Sep 2018 19:51:01 -0400 Subject: Fix NoneType bug introduced by #386 fix --- websocket/_app.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/websocket/_app.py b/websocket/_app.py index 970f3bd..b83d8a6 100644 --- a/websocket/_app.py +++ b/websocket/_app.py @@ -48,7 +48,7 @@ class Dispatcher: def read(self, sock, read_callback, check_callback): while self.app.sock.connected: r, w, e = select.select( - (self.app.sock.sock, ), (), (), self.ping_timeout) # Use a 10 second timeout to avoid to wait forever on close + (self.app.sock.sock, ), (), (), self.ping_timeout) if r: if not read_callback(): break @@ -282,15 +282,15 @@ class WebSocketApp(object): return True def check(): - has_timeout_expired = time.time() - self.last_ping_tm > ping_timeout - has_pong_not_arrived_after_last_ping = self.last_pong_tm - self.last_ping_tm < 0 - has_pong_arrived_too_late = self.last_pong_tm - self.last_ping_tm > ping_timeout - - if (ping_timeout - and self.last_ping_tm - and has_timeout_expired - and (has_pong_not_arrived_after_last_ping or has_pong_arrived_too_late)): - raise WebSocketTimeoutException("ping/pong timed out") + if (ping_timeout): + has_timeout_expired = time.time() - self.last_ping_tm > ping_timeout + has_pong_not_arrived_after_last_ping = self.last_pong_tm - self.last_ping_tm < 0 + has_pong_arrived_too_late = self.last_pong_tm - self.last_ping_tm > ping_timeout + + if (self.last_ping_tm + and has_timeout_expired + and (has_pong_not_arrived_after_last_ping or has_pong_arrived_too_late)): + raise WebSocketTimeoutException("ping/pong timed out") return True dispatcher.read(self.sock.sock, read, check) -- cgit v1.2.1