Hi Martin,
Normally, Python caches modules after they are imported, so when you
import a module for the second time it doesn't actually execute the
code again. If you have 3 modules, "one", "two" and "common", and
"one" and "two" both import "common", "common" should only be loaded
once.
However, there are a few situations where this can break. One is when
the initial script for your application (the one that you run from the
command line) is also imported by other modules. Typically the script
will be loaded twice, once with the name __main__, and once with its
"real" name.
Other possibilities might be import loops, certain uses of "from
<module> import <something>", manipulation of PYTHONPATH/sys.path etc.
It's difficult to know what the cause is without seeing the code. See
also
http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html#the-double-import-trap.
By looking at the value of __name__ and the stack traces when you get
exceptions, you might be able to figure it out.
http://stackoverflow.com/a/4897479/395053 suggests inserting "import
pdb; pdb.set_trace()" above the class definition and using bt to
display backtraces.
In general, the solution is to ensure that your imports are structured
as simply as possible and avoid circular dependencies.
Hope that helps,
Simon
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an