Pythonwin, built 203 for Python 2.4 running on Win98.
The following module, which creates a customized import
function, causes an endless stream of output to the
PythonWin interactive window when imported.
import __builtin__
_import = __import__
def MyImport(name, globs=None, locs=None, fromlist=None):
print "Importing", name
return _import(name, globs, locs, fromlist)
__buitlin__.__import__ = MyImport
The message printed repeatedly is 'importing scriptutils'.
Extending the above module to the following:
import __builtin__
from inspect import getframeinfo
from sys import _getframe
seen = set()
_import = __import__
def MyImport(name, globs=None, locs=None, fromlist=None):
if name not in seen:
seen.add(name)
filenm, lnno, funnm, src, posn = \
getframeinfo(_getframe(1), 1)
print "-----------------"
print "file:", filenm
print "line:", lnno
print "function:", funnm
print src[posn]
return _import(name, globs, locs, fromlist)
__builtin__.__import__ = MyImport
the problem is located to line 326 of module intpyapp.py,
which is method OnUpdateFileCheck of class
InteractivePythonApp. My guess is the output generated
by the customized import handler triggers
OnUpdateFileCheck which imports a module causing more
output and so on.
Here are two fixes among many:
1) Move the import of scriptutils in OnUpdateFileCheck
to the module level.
2) Move the import to an __init__ function of
InteractivePythonApp
class InteractivePythonApp(app.CApp):
def __init__(self):
global __scriptutils
import scriptutils as __scriptutils
app.CApp.__init__(self)
def OnUpdateFileCheck(self, cmdui):
cmdui.Enable(
__scriptutils.GetActiveFileName(0) is not
None )