From 8c07bdc3bc5bb2a6b7fb7d75a8486beb803c4e95 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Fri, 8 May 2015 17:45:59 +0200 Subject: [PATCH] do not timeout if interface is receiving data --- lib/interface.py | 2 +- lib/util.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/interface.py b/lib/interface.py index e9102fc99..e3c789716 100644 --- a/lib/interface.py +++ b/lib/interface.py @@ -287,7 +287,7 @@ class TcpInterface(threading.Thread): self.send_request({'method':'server.version', 'params':[ELECTRUM_VERSION, PROTOCOL_VERSION]}) self.ping_time = time.time() # stop interface if we have been waiting for more than 10 seconds - if self.unanswered_requests and time.time() - self.request_time > 10: + if self.unanswered_requests and time.time() - self.self.request_time > 10 and self.pipe.idle_time() > 10: self.print_error("interface timeout", len(self.unanswered_requests)) self.stop() diff --git a/lib/util.py b/lib/util.py index d9dc06c2c..68e11bded 100644 --- a/lib/util.py +++ b/lib/util.py @@ -323,10 +323,14 @@ class SocketPipe: self.socket = socket self.message = '' self.set_timeout(0.1) + self.recv_time = time.time() def set_timeout(self, t): self.socket.settimeout(t) + def idle_time(self): + return time.time() - self.recv_time + def get(self): while True: response, self.message = parse_json(self.message) @@ -356,6 +360,7 @@ class SocketPipe: self.socket.close() return None self.message += data + self.recv_time = time.time() def send(self, request): out = json.dumps(request) + '\n'