| 3159 | self.status = None |
| 3160 | |
| 3161 | def run(self): |
| 3162 | exists = os.path.exists |
| 3163 | mtime = lambda path: os.stat(path).st_mtime |
| 3164 | files = dict() |
| 3165 | |
| 3166 | for module in list(sys.modules.values()): |
| 3167 | path = getattr(module, '__file__', '') or '' |
| 3168 | if path[-4:] in ('.pyo', '.pyc'): path = path[:-1] |
| 3169 | if path and exists(path): files[path] = mtime(path) |
| 3170 | |
| 3171 | while not self.status: |
| 3172 | if not exists(self.lockfile)\ |
| 3173 | or mtime(self.lockfile) < time.time() - self.interval - 5: |
| 3174 | self.status = 'error' |
| 3175 | thread.interrupt_main() |
| 3176 | for path, lmtime in list(files.items()): |
| 3177 | if not exists(path) or mtime(path) > lmtime: |
| 3178 | self.status = 'reload' |
| 3179 | thread.interrupt_main() |
| 3180 | break |
| 3181 | time.sleep(self.interval) |
| 3182 | |
| 3183 | def __enter__(self): |
| 3184 | self.start() |