In attempting to use Fredrik Lundh's Squeeze utility in
combination with Pmw, I encountered a serious problem
that rendered Pmw unusable.
When the Pmw loader does its clever business of playing
around with sys.modules, pointing the "_Pmw" entry in
sys.modules at the Pmw module, and pointing the "Pmw"
entry in sys.modules at the PmwLoader, this causes
trouble with Squeeze
), and potentially any other utility that makes use of
ihooks. This is because ihooks makes an assumption that
the key in the sys.modules table is the same as the
__name__ of the module it refers to. Normally, this is the
case. But after the PmwLoader switcheroo, this is not
the case, which can be easily seen by executing:
>>> import Pmw
>>> import sys
If ihooks is in operation (as it is with squeeze), it gets
very confused that module referred to by sys.modules
['_Pmw'] is not named '_Pmw'.
The temporary workaround to this problem that we are
currently using is to create a new python file,
PmwGlobal.py, which contains the lines:
sys.modules['_Pmw'].__name__ = '_Pmw'
then we replace all instances of "import Pmw" in our
code with "from PmwGlobal import Pmw". This seems to
fix the problem, and does not seem to have any
negative side effects, but I can't guarantee that it will
never have negative side effects -- it is possible that
some Pmw code may rely on the fact that the _Pmw
module is named "Pmw."
It is not clear to me where the fault lies here -- is this a
bug in Pmw for not making the module name match the
key in sys.modules, or is this a bug in ihooks for
assuming that the module name will match the key? I
would think that if it has no side effects, the Pmw code
should change so that the module name matches the
Log in to post a comment.