[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fab-user] Loading module at runtime works except under fabric
From: |
address@hidden |
Subject: |
[Fab-user] Loading module at runtime works except under fabric |
Date: |
Tue, 16 Apr 2013 11:17:13 -0700 (PDT) |
I've just started experimenting with fabric at work when I ran into a problem.
I wanted some code that I'm planning on running under fabric to be able to load
and instantiate classes dynamically. I created a simple example which runs as
expected when just run under python but fails under fabric.
I think this example is just about as simple as it can be.
I have 2 files in a directory: loader.py & mod1.py. Loader.py dynamically
instantiates a class in mod1.py and calls a method on it. Here is mod1.py
classMyClass1:defrun(self):print"Class1 running"
Here is loader.py:
defrun():mod =__import__('mod1')cls =getattr(mod,'MyClass1')inst
=cls()inst.run()run()
If I run this just straight python: "python loader.py" I see:
Class1running
Which is what you expect. If I then run it under fabric: "fab -f loader.py run"
I see
Class1running Class1running Done.
Which also makes sense, run() is called by fabric AND loader.py when it's
loaded by fabric.
Obviously I don't want the code to run twice but if I remove the explicit call
to run() and run it under fabric, I get
ImportError:Nomodulenamed mod1
Why does running under fabric make a difference? Is there a way to make this
work under fabric?
Thanks.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fab-user] Loading module at runtime works except under fabric,
address@hidden <=