1. cherrypy
  2. CherryPy
Issue #438 resolved

autoreload.py: Server fails to start if a .pyc is imported with no corresponding .py

Anonymous created an issue

If you import a compiled python module that doesn't have a corresponding source module (.py) file in the same directory, cherrypy refuses to start.

The problem is in autoreload.py where the module does an os.stat on a filename (a .py file) without checking to see if the file actually exists, the exception handler then forces a reload on any kind of OSError exception.

{{{ --- autoreload.py 2006-01-10 09:51:06.000000000 -0500 +++ autoreload.py.1 2006-01-11 16:18:09.000000000 -0500 @@ -5,6 +5,7 @@ import sys import time import thread +import errno

RUN_RELOADER = True reloadFiles = [] @@ -22,7 +23,9 @@ filename = filename[:-1] try: mtime = os.stat(filename).st_mtime - except OSError: + except OSError, e: + if e.errno == errno.ENOENT: + continue sys.exit(3) # force reload if filename not in mtimes: mtimes[filename] = mtime


Reported by lyncha@users.sourceforge.net

Comments (4)

  1. Robert Brewer

    Fixed in [1220] by entering "None" in engine.mtimes if the ''first'' attempt at os.stat fails, and then using that None value as a flag to prevent further stat calls. (btw, lyncha's patch wouldn't work, because it would deny reexec on deleted files).

  2. Anonymous

    I don't understand fumanchu's comment. Why should we '''want''' to force a reload just because the .py file for an imported module has gone missing? As long as the code is loaded, why shouldn't we be able to keep using it?

    From my vantage point, lyncha's patch seems to be the correct solution.

  3. Robert Brewer
    Why should we want to force a reload just because the
    .py file for an imported module has gone missing?

    Because in the normal world of Python-without-module-hackery, .py files don't just "go missing"; they're explicitly deleted by the developer. See #261 for the request for this feature.

    You should be able to use engine.autoreload_match to exclude temporary modules.

  4. Log in to comment