(self, evt)
| 41 | self.callbacks.append(f) |
| 42 | |
| 43 | def onChanged(self, evt): |
| 44 | path = evt.src_path |
| 45 | ext = path.rsplit(".", 1)[-1] |
| 46 | if ext not in ["py", "json"] or "Test" in path or time.time() - self.last_chaged < 1.0: |
| 47 | return False |
| 48 | self.last_chaged = time.time() |
| 49 | if os.path.isfile(path): |
| 50 | time_modified = os.path.getmtime(path) |
| 51 | else: |
| 52 | time_modified = 0 |
| 53 | self.log.debug("File changed: %s reloading source code (modified %.3fs ago)" % (evt, time.time() - time_modified)) |
| 54 | if time.time() - time_modified > 5: # Probably it's just an attribute change, ignore it |
| 55 | return False |
| 56 | |
| 57 | time.sleep(0.1) # Wait for lock release |
| 58 | for callback in self.callbacks: |
| 59 | try: |
| 60 | callback() |
| 61 | except Exception as err: |
| 62 | self.log.exception(err) |
| 63 | |
| 64 | def stop(self): |
| 65 | if enabled: |
no outgoing calls