possible bug in cherrypy.lib.autoreloader

I

infidel

I may have found the source of my infinite loop when importing kid
modules from my cherrypy server. Here is some code from the
autoreloader module of cherrypy:

def reloader_thread():
mtimes = {}

def fileattr(m):
return getattr(m, "__file__", None)

while RUN_RELOADER:
for filename in map(fileattr, sys.modules.values()) +
reloadFiles:
if filename:
if filename.endswith(".pyc"):
filename = filename[:-1]
try:
mtime = os.stat(filename).st_mtime
except OSError:
sys.exit(3) # force reload
if filename not in mtimes:
mtimes[filename] = mtime
continue
if mtime > mtimes[filename]:
sys.exit(3) # force reload
time.sleep(1)

So what happens if one of my modules is a kid template named
'login.kid'? kid compiles the template to login.pyc, which means the
os.stat call in this function will be passed 'login.py' which does not
exist.
 
I

infidel

Ok, so it turns out that the problem the cherrypy.lib.autoreload module
is having, is that kid imports elementtree and on my machine the
elementtree modules are inside a zip file (.egg). So the "path" to the
elementtree __init__.py file is not a valid OS path because everything
after the .egg file is inside the file.

Is there a quick way of determining that a module was imported from a
zip file, or that a module's __file__ attribute is a valid path as far
as Python is concerned, even though it doesn't exist to the OS?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top