aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bb/event.py
diff options
context:
space:
mode:
authorChris Larson <chris_larson@mentor.com>2011-04-04 11:31:39 -0700
committerChris Larson <chris_larson@mentor.com>2011-04-04 14:23:09 -0700
commitfaf682dfc23b7ef2ece04f7d50f9741224bb3bb0 (patch)
tree3ccbd1da62c1f248c5d8332414830bb892fad165 /lib/bb/event.py
parentbe647dac9d458ee4b289ff5f66ed95b311d398d8 (diff)
downloadbitbake-faf682dfc23b7ef2ece04f7d50f9741224bb3bb0.tar.gz
event: improve output when eventhandler exec fails
- Name the event handler by its actual name, so the traceback shows it rather than 'tmpHandler'. - Rather than immediately aborting when encountering an event handler error, display an error message and try to continue. - Show a traceback for ordinary exceptions, skipping the first entry in the traceback, so it only shows the useful information. - Show an error, but no traceback, for SystemExit with a code other than 0. - For for SystemExit with a code of 0, simply continue silently. Signed-off-by: Chris Larson <chris_larson@mentor.com>
Diffstat (limited to 'lib/bb/event.py')
-rw-r--r--lib/bb/event.py42
1 files changed, 31 insertions, 11 deletions
diff --git a/lib/bb/event.py b/lib/bb/event.py
index 289217aa..498a424a 100644
--- a/lib/bb/event.py
+++ b/lib/bb/event.py
@@ -38,6 +38,8 @@ import bb.utils
worker_pid = 0
worker_pipe = None
+logger = logging.getLogger('BitBake.Event')
+
class Event(object):
"""Base class for events"""
@@ -59,18 +61,35 @@ _ui_handler_seq = 0
bb.utils._context["NotHandled"] = NotHandled
bb.utils._context["Handled"] = Handled
+def execute_handler(name, handler, event, d):
+ event.data = d
+ try:
+ ret = handler(event)
+ except Exception:
+ etype, value, tb = sys.exc_info()
+ logger.error("Execution of event handler '%s' failed" % name,
+ exc_info=(etype, value, tb.tb_next))
+ raise
+ except SystemExit as exc:
+ if exc.code != 0:
+ logger.error("Execution of event handler '%s' failed" % name)
+ raise
+ finally:
+ del event.data
+
+ if ret is not None:
+ warnings.warn("Using Handled/NotHandled in event handlers is deprecated",
+ DeprecationWarning, stacklevel = 2)
+
def fire_class_handlers(event, d):
if isinstance(event, logging.LogRecord):
return
- for handler in _handlers.itervalues():
- event.data = d
- ret = handler(event)
- if ret is not None:
- warnings.warn("Using Handled/NotHandled in event handlers is deprecated",
- DeprecationWarning, stacklevel = 2)
-
- del event.data
+ for name, handler in _handlers.iteritems():
+ try:
+ execute_handler(name, handler, event, d)
+ except BaseException:
+ continue
ui_queue = []
@atexit.register
@@ -142,11 +161,12 @@ def register(name, handler):
if handler is not None:
# handle string containing python code
if isinstance(handler, basestring):
- tmp = "def tmpHandler(e):\n%s" % handler
- comp = bb.utils.better_compile(tmp, "tmpHandler(e)", "bb.event._registerCode")
+ tmp = "def %s(e):\n%s" % (name, handler)
+ comp = bb.utils.better_compile(tmp, "%s(e)" % name,
+ "bb.event._registerCode")
env = {}
bb.utils.simple_exec(comp, env)
- func = bb.utils.better_eval("tmpHandler", env)
+ func = bb.utils.better_eval(name, env)
_handlers[name] = func
else:
_handlers[name] = handler