daemon: Improve running session state change hooks.
This commit is contained in:
parent
0a16ef13db
commit
5838814f07
1 changed files with 8 additions and 5 deletions
|
@ -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:
|
||||||
|
|
Loading…
Reference in a new issue