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 <[email protected]>

---
 ryu/base/app_manager.py | 12 +++++++++++-
 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 cc51008..0a35e91 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 ce5e150..b77465b 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,
-- 

Best,
Victor
--
Victor J. Orlikowski <> vjo@[cs.]duke.edu

Attachment: 0001-Wrap-handler-calls-in-the-event-loop-in-a-try-except.patch
Description: 0001-Wrap-handler-calls-in-the-event-loop-in-a-try-except.patch

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to