diff options
author | Victor J. Orlikowski <vjo@duke.edu> | 2016-02-26 11:24:01 -0500 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-02-27 22:03:38 +0900 |
commit | f1f0ca2d1688d25924854a635becdcbfef95a5cd (patch) | |
tree | 25cbb7f8c88de7883f28ca6764ed481987b02f7f | |
parent | db1c93249b5ab5827e396760e9db1f75a614467b (diff) |
Wrap handler calls in the event loop in a try/except and log exceptions
In order to prevent an exception from terminating the execution of the
event loop. Wrapper name also added to hub.py for GreenletExit.
Signed-off-by: Victor J. Orlikowski <vjo@duke.edu>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/base/app_manager.py | 12 | ||||
-rw-r--r-- | ryu/lib/hub.py | 7 |
2 files changed, 15 insertions, 4 deletions
diff --git a/ryu/base/app_manager.py b/ryu/base/app_manager.py index cc510087..0a35e915 100644 --- a/ryu/base/app_manager.py +++ b/ryu/base/app_manager.py @@ -286,7 +286,17 @@ class RyuApp(object): continue handlers = self.get_handlers(ev, state) for handler in handlers: - handler(ev) + try: + handler(ev) + except hub.TaskExit: + # Normal exit. + # Propagate upwards, so we leave the event loop. + raise + except: + LOG.exception('%s: Exception occurred during handler processing. ' + 'Backtrace from offending handler ' + '[%s] servicing event [%s] follows.', + self.name, handler.__name__, ev.__class__.__name__) def _send_event(self, ev, state): self._events_sem.acquire() diff --git a/ryu/lib/hub.py b/ryu/lib/hub.py index ce5e150f..b77465bf 100644 --- a/ryu/lib/hub.py +++ b/ryu/lib/hub.py @@ -50,7 +50,7 @@ if HUB_TYPE == 'eventlet': # by not propergating an exception to the joiner. try: func(*args, **kwargs) - except greenlet.GreenletExit: + except TaskExit: pass except: # log uncaught exception. @@ -67,7 +67,7 @@ if HUB_TYPE == 'eventlet': # by not propergating an exception to the joiner. try: func(*args, **kwargs) - except greenlet.GreenletExit: + except TaskExit: pass except: # log uncaught exception. @@ -87,13 +87,14 @@ if HUB_TYPE == 'eventlet': # greenthread try: t.wait() - except greenlet.GreenletExit: + except TaskExit: pass Queue = eventlet.queue.LightQueue QueueEmpty = eventlet.queue.Empty Semaphore = eventlet.semaphore.Semaphore BoundedSemaphore = eventlet.semaphore.BoundedSemaphore + TaskExit = greenlet.GreenletExit class StreamServer(object): def __init__(self, listen_info, handle=None, backlog=None, |