AlertManager will now cancel all pending delayedCalls prior to stopping.

This commit is contained in:
Andrew Resch 2010-03-20 19:12:28 -07:00
parent 16b832f7ab
commit 606b623d73
1 changed files with 9 additions and 1 deletions

View File

@ -66,9 +66,17 @@ class AlertManager(component.Component):
# handlers is a dictionary of lists {"alert_type": [handler1,h2,..]}
self.handlers = {}
self.delayed_calls = []
def update(self):
self.delayed_calls = [dc for dc in self.delayed_calls if dc.active()]
self.handle_alerts()
def stop(self):
for dc in self.delayed_calls:
dc.cancel()
self.delayed_calls = []
def register_handler(self, alert_type, handler):
"""
Registers a function that will be called when 'alert_type' is pop'd
@ -117,7 +125,7 @@ class AlertManager(component.Component):
if alert_type in self.handlers:
for handler in self.handlers[alert_type]:
if not wait:
reactor.callLater(0, handler, alert)
self.delayed_calls.append(reactor.callLater(0, handler, alert))
else:
handler(alert)