Permalink
Browse files

When a service is forceStarted, wrap all its event handlers with an e…

…rror trap function to prevent unhandled exceptions from bubbling up into the event dispatcher
  • Loading branch information...
1 parent 8677beb commit 58d850df354167bc3de1db0817e0ff871d164cb7 @kg committed Dec 27, 2010
Showing with 27 additions and 1 deletion.
  1. +27 −1 Common/common.service.py
View
@@ -1,4 +1,4 @@
-from shootblues.common import log
+from shootblues.common import log, showException
runningServices = {}
@@ -11,6 +11,31 @@ def get(serviceName):
return result
+def wrapMethod(methodName, innerMethod):
+ def wrapper(*args, **kwargs):
+ result = None
+
+ try:
+ result = innerMethod(*args, **kwargs)
+ except Exception, e:
+ showException()
+
+ return result
+
+ wrapper.func_name = methodName
+ return wrapper
+
+def makeServiceThunk(serviceInstance):
+ result = serviceInstance
+
+ ne = getattr(serviceInstance, "__notifyevents__", [])
+ for evt in ne:
+ innerMethod = getattr(result, evt, None)
+ if innerMethod:
+ setattr(result, evt, wrapMethod(evt, innerMethod))
+
+ return result
+
def forceStop(serviceName):
global runningServices
@@ -43,6 +68,7 @@ def forceStart(serviceName, serviceType):
result = serviceType()
setattr(result, "state", service.SERVICE_RUNNING)
+ result = makeServiceThunk(result)
runningServices[serviceName] = result
ne = getattr(result, "__notifyevents__", [])

0 comments on commit 58d850d

Please sign in to comment.