Browse Source

prevent busy looping

283
ThomasV 8 years ago
parent
commit
29e2570d3d
  1. 7
      lib/interface.py
  2. 2
      lib/network.py

7
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))

2
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):

Loading…
Cancel
Save