daemon: Improve running session state change hooks.

This commit is contained in:
tgoff0 2015-05-22 00:56:24 +00:00
parent 0a16ef13db
commit 5838814f07

View file

@ -324,12 +324,15 @@ class Session(object):
self._hooks = {} self._hooks = {}
def run_state_hooks(self, state): def run_state_hooks(self, state):
try: if state not in self._state_hooks:
hooks = self._state_hooks[state] return
for hook in hooks: for hook in self._state_hooks[state]:
try:
hook(state) hook(state)
except KeyError: except Exception, e:
pass self.warn("ERROR: exception occured when running %s state "
"hook: %s: %s" % (coreapi.state_name(state),
hook, e))
def add_state_hook(self, state, hook): def add_state_hook(self, state, hook):
try: try: