def need_processing(self):
"""A utility to help determine which connections need
processing. Returns a triple of lists containing those connections that
0) need to read from the network, 1) need to write to the network, 2)
waiting for pending timers to expire. The timer list is sorted with
the connection next expiring at index 0.
"""
readers = []
writers = []
timer_heap = []
for c in iter(self._connections.values()):
if c.needs_input > 0:
readers.append(c)
if c.has_output > 0:
writers.append(c)
if c.deadline:
heapq.heappush(timer_heap, (c.next_tick, c))
timers = []
while timer_heap:
x = heapq.heappop(timer_heap)
timers.append(x[1])
return (readers, writers, timers)
评论列表
文章目录