Navigates back the stack to locate the module instead of relying on
inspect to locate the module based on the file name.

This patch is suggested by papostolescu as Pull Request(*1)
on GitHub.
   (*1) https://github.com/osrg/ryu/pull/26

Signed-off-by: IWASE Yusuke <iwase.yusu...@gmail.com>
---
  ryu/controller/handler.py | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/ryu/controller/handler.py b/ryu/controller/handler.py
index f1fb707..cda27bc 100644
--- a/ryu/controller/handler.py
+++ b/ryu/controller/handler.py
@@ -148,6 +148,7 @@ def register_service(service):
      This mechanism is used to e.g. automatically start ofp_handler if
      there are applications consuming OFP events.
      """
-    frm = inspect.stack()[1]
-    m = inspect.getmodule(frm[0])
+    frame = inspect.currentframe()
+    m_name = frame.f_back.f_globals['__name__']
+    m = sys.modules[m_name]
      m._SERVICE_NAME = service
-- 
2.7.4



------------------------------------------------------------------------------
_______________________________________________
Ryu-devel mailing list
Ryu-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to