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.

(Bitbake rev: faf682dfc23b7ef2ece04f7d50f9741224bb3bb0)

Signed-off-by: Chris Larson <chris_larson@mentor.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Chris Larson 2011-04-04 11:31:39 -07:00 committed by Richard Purdie
parent 8cf28d706b
commit 37cb4cc02b
1 changed files with 31 additions and 11 deletions

View File

@ -37,6 +37,8 @@ import bb.utils
worker_pid = 0
worker_pipe = None
logger = logging.getLogger('BitBake.Event')
class Event(object):
"""Base class for events"""
@ -58,18 +60,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
@ -141,11 +160,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