Iwan Vosloo wrote: > 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...
Try putting an "import pdb; pdb.set_trace()" on top of the decimal module. Then you can see whenever it gets imported new, and with "bt" get a backtrace, and you can inspect (and thus eventually compare) the various states of sys.path and sys.modules. Diez -- http://mail.python.org/mailman/listinfo/python-list