Commit 011d101d authored by Kenneth Giusti's avatar Kenneth Giusti

clean up timer handling

parent a074a873
......@@ -405,7 +405,7 @@ class Connection(Endpoint):
for l in tmp.values():
l.destroy()
assert(len(self._receiver_links) == 0)
self._timers = None
self._timers.clear()
self._timers_heap = None
self._container.remove_connection(self._name)
self._container = None
......@@ -757,15 +757,13 @@ class Connection(Endpoint):
def _add_timer(self, deadline, callback):
callbacks = self._timers.get(deadline)
if callbacks:
callbacks.add(callback)
else:
if callbacks is None:
callbacks = set()
callbacks.add(callback)
self._timers[deadline] = callbacks
heapq.heappush(self._timers_heap, deadline)
if deadline < self._next_deadline:
self._next_deadline = deadline
callbacks.add(callback)
def _cancel_timer(self, deadline, callback):
callbacks = self._timers.get(deadline)
......@@ -778,9 +776,8 @@ class Connection(Endpoint):
self._timers_heap[0] <= now):
deadline = heapq.heappop(self._timers_heap)
callbacks = self._timers.get(deadline)
if callbacks:
for cb in callbacks:
cb()
while callbacks:
callbacks.pop()()
del self._timers[deadline]
return self._timers_heap[0] if self._timers_heap else 0
......
......@@ -31,8 +31,6 @@ class Container(object):
def __init__(self, name, properties=None):
self._name = name
self._connections = {}
self._timer_heap = [] # (next_tick, connection)
self._need_processing = set()
self._properties = properties
def destroy(self):
......
......@@ -394,8 +394,8 @@ class SenderLink(_Link):
self.handle = handle
self.deadline = deadline
self.link._send_requests[self.tag] = self
if deadline:
self.link._connection._add_timer(deadline, self)
if self.deadline:
self.link._connection._add_timer(self.deadline, self)
def __call__(self):
"""Invoked by Connection on timeout (now <= deadline)."""
......@@ -403,7 +403,7 @@ class SenderLink(_Link):
def destroy(self, state, info):
"""Invoked on final completion of send."""
if self.deadline and state != SenderLink.TIMED_OUT:
if self.deadline:
self.link._connection._cancel_timer(self.deadline, self)
if self.tag in self.link._send_requests:
del self.link._send_requests[self.tag]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment