commit 29e2570d3d45ede9e555f8667bad840fd5cf74b3
parent 6055d4b2fd145052247d55ff30f0c80168ebceff
Author: ThomasV <thomasv@electrum.org>
Date: Mon, 9 Jan 2017 16:36:05 +0100
prevent busy looping
Diffstat:
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/lib/interface.py b/lib/interface.py
@@ -257,10 +257,15 @@ class Interface(util.PrintError):
self.request_time = time.time()
self.unsent_requests.append(args)
+ def num_requests(self):
+ '''Keep unanswered requests below 100'''
+ n = 100 - len(self.unanswered_requests)
+ return min(n, len(self.unsent_requests))
+
def send_requests(self):
'''Sends queued requests. Returns False on failure.'''
make_dict = lambda (m, p, i): {'method': m, 'params': p, 'id': i}
- n = 100 - len(self.unanswered_requests)
+ n = self.num_requests()
wire_requests = self.unsent_requests[0:n]
try:
self.pipe.send_all(map(make_dict, wire_requests))
diff --git a/lib/network.py b/lib/network.py
@@ -788,7 +788,7 @@ class Network(util.DaemonThread):
time.sleep(0.1)
return
rin = [i for i in self.interfaces.values()]
- win = [i for i in self.interfaces.values() if i.unsent_requests]
+ win = [i for i in self.interfaces.values() if i.num_requests()]
try:
rout, wout, xout = select.select(rin, win, [], 0.1)
except socket.error as (code, msg):