Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Ticket #438 (defect)

Opened 3 years ago

Last modified 2 years ago

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

Status: closed (fixed)

Reported by: lyncha@users.sourceforge.net Assigned to: rdelon
Priority: normal Milestone:
Component: CherryPy code Keywords:
Cc:

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

Attachments

autoreload.patch (0.6 kB) - added by lyncha@users.sourceforge.net on 01/11/06 15:51:14.
patch

Change History

01/11/06 15:51:14: Modified by lyncha@users.sourceforge.net

  • attachment autoreload.patch added.

patch

08/05/06 18:26:29: Modified by fumanchu

  • status changed from new to closed.
  • resolution set to fixed.

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).

09/07/06 12:30:19: Modified by timr@probo.com

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.

09/07/06 18:27:06: Modified by fumanchu

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.

Hosted by WebFaction

Log in as guest/cpguest to create tickets