Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix Reloader #63

Closed
wants to merge 7 commits into from

1 participant

@vonbetz
Change Reloader to check for changes and reload all user created modules
instead of just reloading the ones that changed.  This fixes the issue
where modules contain references to other modules which are not updated
when reload is called.
zak and others added some commits
zak Change Reloader to check for changes and reload all user created modules
instead of just reloading the ones that changed.  This fixes the issue
where modules contain references to other modules which are not updated
when reload is called.
0e0d938
zak Change Reloader to check for changes and reload all user created modules
instead of just reloading the ones that changed.  This fixes the issue
where modules contain references to other modules which are not updated
when reload is called.
3cc2868
zak Merge branch 'master' of https://github.com/vonbetz/webpy b696222
zak reload the modules that change twice. This fixes the bug that is
introduced by loading the modules in arbitrary order where
Module A imports Module B
then the following sequence occurs:
-Module A imports Module B
-Module B changes
-Module A is reloaded (using the already loaded old version of Module B)
-Module B is reloaded
5ee5f53
zak Merge remote branch 'upstream/master' c716483
zak Save one hit on the database per request for session lookup and
expiration check.  Code clarity is largely unaffected.
04e72cf
zak accidentally a whole word in the debug page. ddb6f94
@vonbetz vonbetz closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 9, 2011
  1. Change Reloader to check for changes and reload all user created modules

    zak authored
    instead of just reloading the ones that changed.  This fixes the issue
    where modules contain references to other modules which are not updated
    when reload is called.
  2. Change Reloader to check for changes and reload all user created modules

    zak authored
    instead of just reloading the ones that changed.  This fixes the issue
    where modules contain references to other modules which are not updated
    when reload is called.
Commits on May 16, 2011
  1. reload the modules that change twice. This fixes the bug that is

    zak authored
    introduced by loading the modules in arbitrary order where
    Module A imports Module B
    then the following sequence occurs:
    -Module A imports Module B
    -Module B changes
    -Module A is reloaded (using the already loaded old version of Module B)
    -Module B is reloaded
  2. Merge remote branch 'upstream/master'

    zak authored
  3. Save one hit on the database per request for session lookup and

    zak authored
    expiration check.  Code clarity is largely unaffected.
Commits on May 27, 2011
This page is out of date. Refresh to see the latest.
Showing with 34 additions and 20 deletions.
  1. +22 −7 web/application.py
  2. +1 −1  web/debugerror.py
  3. +11 −12 web/session.py
View
29 web/application.py
@@ -633,32 +633,47 @@ def internal(self, arg):
class Reloader:
"""Checks to see if any loaded modules have changed on disk and,
- if so, reloads them.
+ if so, reloads all user modules.
"""
def __init__(self):
self.mtimes = {}
def __call__(self):
+ changed = False
for mod in sys.modules.values():
- self.check(mod)
+ changed = changed or self.check(mod)
+ if changed:
+ for modName, mod in sys.modules.items():
+ if not hasattr(mod, '__file__') or \
+ mod.__file__.startswith(sys.prefix) or \
+ modName.startswith('web.'):
+ continue
+ try:
+ reload(mod)
+ except ImportError, msg:
+ pass
def check(self, mod):
+ changed = False
+
try:
mtime = os.stat(mod.__file__).st_mtime
except (AttributeError, OSError, IOError):
- return
+ return False
if mod.__file__.endswith('.pyc') and os.path.exists(mod.__file__[:-1]):
mtime = max(os.stat(mod.__file__[:-1]).st_mtime, mtime)
if mod not in self.mtimes:
self.mtimes[mod] = mtime
elif self.mtimes[mod] < mtime:
- try:
+ try:
reload(mod)
- self.mtimes[mod] = mtime
- except ImportError:
+ except ImportError, msg:
pass
-
+ changed = True
+ self.mtimes[mod] = mtime
+ return changed
+
if __name__ == "__main__":
import doctest
doctest.testmod()
View
2  web/debugerror.py
@@ -217,7 +217,7 @@
<div id="explanation">
<p>
You're seeing this error because you have <code>web.config.debug</code>
- set to <code>True</code>. Set that to <code>False</code> if you don't to see this.
+ set to <code>True</code>. Set that to <code>False</code> if you don't want to see this.
</p>
</div>
View
23 web/session.py
@@ -94,12 +94,18 @@ def _load(self):
if self.session_id and not self._valid_session_id(self.session_id):
self.session_id = None
- self._check_expiry()
+ # fetch session from store and check expiry
if self.session_id:
- d = self.store[self.session_id]
- self.update(d)
- self._validate_ip()
-
+ try:
+ d = self.store[self.session_id]
+ self.update(d)
+ self._validate_ip()
+ except KeyError:
+ if self._config.ignore_expiry:
+ self.session_id = None
+ else:
+ return self.expired()
+
if not self.session_id:
self.session_id = self._generate_session_id()
@@ -111,13 +117,6 @@ def _load(self):
self.ip = web.ctx.ip
- def _check_expiry(self):
- # check for expiry
- if self.session_id and self.session_id not in self.store:
- if self._config.ignore_expiry:
- self.session_id = None
- else:
- return self.expired()
def _validate_ip(self):
# check for change of IP
Something went wrong with that request. Please try again.