diff --git a/lib/interface.py b/lib/interface.py index 68658f0f5..d530a5e4d 100644 --- 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 index 322d81a79..bf4421774 100644 --- 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):