possible bug in cherrypy.lib.autoreloader

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • infidel

    #1

    possible bug in cherrypy.lib.autoreloader

    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.val ues()) +
    reloadFiles:
    if filename:
    if filename.endswi th(".pyc"):
    filename = filename[:-1]
    try:
    mtime = os.stat(filenam e).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.

  • infidel

    #2
    Re: possible bug in cherrypy.lib.au toreload

    Ok, so it turns out that the problem the cherrypy.lib.au toreload 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?

    Comment

    Working...