Otherwise, AppManager.run_apps fails to terminate.

Signed-off-by: IWAMOTO Toshihiro <[email protected]>
---
 ryu/base/app_manager.py                 | 12 ++++++++++++
 ryu/services/protocols/ovsdb/manager.py |  1 +
 2 files changed, 13 insertions(+)

diff --git a/ryu/base/app_manager.py b/ryu/base/app_manager.py
index 5b63e8c..3d5d895 100644
--- a/ryu/base/app_manager.py
+++ b/ryu/base/app_manager.py
@@ -156,6 +156,7 @@ class RyuApp(object):
         self.event_handlers = {}        # ev_cls -> handlers:list
         self.observers = {}     # ev_cls -> observer-name -> states:set
         self.threads = []
+        self.main_thread = None
         self.events = hub.Queue(128)
         if hasattr(self.__class__, 'LOGGER_NAME'):
             self.logger = logging.getLogger(self.__class__.LOGGER_NAME)
@@ -176,10 +177,20 @@ class RyuApp(object):
         self.threads.append(hub.spawn(self._event_loop))
 
     def stop(self):
+        if self.main_thread:
+            hub.kill(self.main_thread)
         self.is_active = False
         self._send_event(self._event_stop, None)
         hub.joinall(self.threads)
 
+    def set_main_thread(self, thread):
+        """
+        Set self.main_thread so that stop() can terminate it.
+
+        Only AppManager.instantiate_apps should call this function.
+        """
+        self.main_thread = thread
+
     def register_handler(self, ev_cls, handler):
         assert callable(handler)
         self.event_handlers.setdefault(ev_cls, [])
@@ -490,6 +501,7 @@ class AppManager(object):
         for app in self.applications.values():
             t = app.start()
             if t is not None:
+                app.set_main_thread(t)
                 threads.append(t)
         return threads
 
diff --git a/ryu/services/protocols/ovsdb/manager.py 
b/ryu/services/protocols/ovsdb/manager.py
index 7b1d5c8..e12935b 100644
--- a/ryu/services/protocols/ovsdb/manager.py
+++ b/ryu/services/protocols/ovsdb/manager.py
@@ -118,6 +118,7 @@ class OVSDB(app_manager.RyuApp):
         return t
 
     def stop(self):
+        # TODO main_thread should be stopped first, not from super().stop
         for client in self._clients.values():
             client.stop()
 
-- 
2.1.4


------------------------------------------------------------------------------
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to