On Sat, Oct 13, 2012 at 02:44:32AM +0900, FUJITA Tomonori wrote:
> On Fri, 12 Oct 2012 17:28:50 +0900
> Isaku Yamahata <[email protected]> wrote:
> 
> > On Fri, Oct 12, 2012 at 07:39:21AM +0900, FUJITA Tomonori wrote:
> >> On Thu, 11 Oct 2012 17:17:15 +0900
> >> Isaku Yamahata <[email protected]> wrote:
> >> 
> >> > Since import_module() isn't aware of cwd, so it may result in double 
> >> > import.
> >> > Avoid double import.
> >> 
> >> Elaborate how it happens, please.
> > 
> > I'll add the following to the commit message.
> > 
> > In the following example, the first one(ryu.app.event_dumper) imports the
> > module, ryu.app.event_dumper, relative to ryu/.., the second one
> > (ryu/app/event_dumper.py) imports the module, event_dumper, relative to
> > ryu/app. Python thinks that they are different modules.
> > Although it doesn't make much sense to instantiate same application twice,
> > I don't think of any reason to prevent it. And it is difficult to understand
> > what's happening.
> 
> I can see what problem you try to solve but I'm not sure you did. Even
> with this patch, I hit the same problem with:
> 
> $ pwd
> /home/fujita/git/ryu/ryu/app
> $ ryu-manager --app_lists=ryu.app.event_dumper --app_lists=event_dumper.py
> 
> 
> If we can fix the problem completely, I can see the benefit. But this
> patch fixes the problem partially.

How about this approach? pseudo code
The issue is, given application can be loaded both from (unmodified) sys.path
and from its parent directly when it endswith('.py')
So how about trying to load module when relative path is given?

pseudo code like
if not endswith('.py'):
    __import__()
    return

if relative path:
     remove '.py'
     replace '/' with '.'
     try:
         __import__()
         return
     except:
         pass
     path = abspath(path)

# abs path case
sys.path.append()
__import__()

-- 
yamahata

------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to