MCPcopy Index your code
hub / github.com/webpy/webpy / Reloader

Class Reloader

web/application.py:765–806  ·  view source on GitHub ↗

Checks to see if any loaded modules have changed on disk and, if so, reloads them.

Source from the content-addressed store, hash-verified

763
764
765class Reloader:
766 """Checks to see if any loaded modules have changed on disk and,
767 if so, reloads them.
768 """
769
770 """File suffix of compiled modules."""
771 if sys.platform.startswith("java"):
772 SUFFIX = "$py.class"
773 else:
774 SUFFIX = ".pyc"
775
776 def __init__(self):
777 self.mtimes = {}
778
779 def __call__(self):
780 sys_modules = list(sys.modules.values())
781 for mod in sys_modules:
782 self.check(mod)
783
784 def check(self, mod):
785 # jython registers java packages as modules but they either
786 # don't have a __file__ attribute or its value is None
787 if not (mod and hasattr(mod, "__file__") and mod.__file__):
788 return
789
790 try:
791 mtime = os.stat(mod.__file__).st_mtime
792 except OSError:
793 return
794 if mod.__file__.endswith(self.__class__.SUFFIX) and os.path.exists(
795 mod.__file__[:-1]
796 ):
797 mtime = max(os.stat(mod.__file__[:-1]).st_mtime, mtime)
798
799 if mod not in self.mtimes:
800 self.mtimes[mod] = mtime
801 elif self.mtimes[mod] < mtime:
802 try:
803 reload(mod)
804 self.mtimes[mod] = mtime
805 except ImportError:
806 pass
807
808
809if __name__ == "__main__":

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected