def deliver_messages(self, timeout=.1):
"""
Allow peers to communicate.
The strategy is as follows:
1. Measure the amount of working threads in the threadpool
2. After 10 milliseconds, check if we are down to 0 twice in a row
3. If not, go back to handling calls (step 2) or return, if the timeout has been reached
:param timeout: the maximum time to wait for messages to be delivered
"""
rtime = 0
probable_exit = False
while (rtime < timeout):
yield self.sleep(.01)
rtime += .01
if len(reactor.getThreadPool().working) == 0:
if probable_exit:
break
probable_exit = True
else:
probable_exit = False
评论列表
文章目录