From dd06396803df422bc50320a8a7f8b3d53557e060 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 11 Sep 2013 16:53:25 +0900 Subject: [PATCH] import_module: deal with cases mod.__file__ is not accessible Signed-off-by: YAMAMOTO Takashi Signed-off-by: FUJITA Tomonori --- ryu/utils.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ryu/utils.py b/ryu/utils.py index e8fc7a22..1e1aa490 100644 --- a/ryu/utils.py +++ b/ryu/utils.py @@ -47,8 +47,12 @@ def chop_py_suffix(p): def _likely_same(a, b): - if os.path.samefile(a, b): - return True + try: + if os.path.samefile(a, b): + return True + except OSError: + # m.__file__ is not always accessible. eg. egg + return False if chop_py_suffix(a) == chop_py_suffix(b): return True return False @@ -57,6 +61,8 @@ def _likely_same(a, b): def _find_loaded_module(modpath): # copy() to avoid RuntimeError: dictionary changed size during iteration for k, m in sys.modules.copy().iteritems(): + if k == '__main__': + continue if not hasattr(m, '__file__'): continue if _likely_same(m.__file__, modpath):