How to debug this import problem?

Iwan Vosloo iwan at reahl.org
Fri May 8 19:01:57 CEST 2009


Hi there,

We have a rather complicated program which does a bit of os.chdir and
sys.path manipulations.  In between all of this, it imports the decimal
module several times.

However, it imports a new instance of decimal sometimes.  (Which is a
problem, since a decimal.Decimal (imported at point A) now is not the
same as that imported somewhere else.

In trying to figure out what's happening, we've changed the code in
decimal to print out id(sys) when decimal gets imported.  This also
gives back different values at different times.  My suspicion is that
when importing python tries to check sys.modules - but each time sys is
a different sys already.

Any ideas of how we can gather more data to find out exactly what causes
this? The path manipulations is a suspect, but unfortunately we cannot
remove it.  If we can trace the problem from the import end though, we
may be able to isolate the exact one which is the problem.

This code incidentally also runs in a virtualenv environment AND uses
setuptools.  None of these complications can be removed...

Regards
- Iwan




More information about the Python-list mailing list