| 3747 | self.status = None |
| 3748 | |
| 3749 | def run(self): |
| 3750 | exists = os.path.exists |
| 3751 | mtime = lambda p: os.stat(p).st_mtime |
| 3752 | files = dict() |
| 3753 | |
| 3754 | for module in list(sys.modules.values()): |
| 3755 | path = getattr(module, '__file__', '') or '' |
| 3756 | if path[-4:] in ('.pyo', '.pyc'): path = path[:-1] |
| 3757 | if path and exists(path): files[path] = mtime(path) |
| 3758 | |
| 3759 | while not self.status: |
| 3760 | if not exists(self.lockfile)\ |
| 3761 | or mtime(self.lockfile) < time.time() - self.interval - 5: |
| 3762 | self.status = 'error' |
| 3763 | thread.interrupt_main() |
| 3764 | for path, lmtime in list(files.items()): |
| 3765 | if not exists(path) or mtime(path) > lmtime: |
| 3766 | self.status = 'reload' |
| 3767 | thread.interrupt_main() |
| 3768 | break |
| 3769 | time.sleep(self.interval) |
| 3770 | |
| 3771 | def __enter__(self): |
| 3772 | self.start() |