| 4145 | self.status = None |
| 4146 | |
| 4147 | def run(self): |
| 4148 | exists = os.path.exists |
| 4149 | mtime = lambda p: os.stat(p).st_mtime |
| 4150 | files = dict() |
| 4151 | |
| 4152 | for module in list(sys.modules.values()): |
| 4153 | path = getattr(module, '__file__', '') or '' |
| 4154 | if path[-4:] in ('.pyo', '.pyc'): path = path[:-1] |
| 4155 | if path and exists(path): files[path] = mtime(path) |
| 4156 | |
| 4157 | while not self.status: |
| 4158 | if not exists(self.lockfile)\ |
| 4159 | or mtime(self.lockfile) < time.time() - self.interval - 5: |
| 4160 | self.status = 'error' |
| 4161 | thread.interrupt_main() |
| 4162 | for path, lmtime in list(files.items()): |
| 4163 | if not exists(path) or mtime(path) > lmtime: |
| 4164 | self.status = 'reload' |
| 4165 | thread.interrupt_main() |
| 4166 | break |
| 4167 | time.sleep(self.interval) |
| 4168 | |
| 4169 | def __enter__(self): |
| 4170 | self.start() |