diff options
author | Michaël Ball <michael.ball@gmail.com> | 2017-08-19 11:18:09 +0100 |
---|---|---|
committer | Michaël Ball <michael.ball@gmail.com> | 2017-08-19 11:18:09 +0100 |
commit | d371717e04e116ed140698195c2d1f089c09b65f (patch) | |
tree | bc9452616f80e0fedc78e7fc38d12e3bc413ab3f | |
parent | e9c19e05c6ae79d70f4dcfd8543ff2036147e20f (diff) |
Better way of running library watcher
-rw-r--r-- | app.py | 14 | ||||
-rw-r--r-- | watcher.py | 3 |
2 files changed, 11 insertions, 6 deletions
@@ -15,10 +15,18 @@ APP = create_app() if __name__ == "__main__": config = configparser.ConfigParser() config.read("mach2.ini") - watcher = spawn(LibraryWatcher, config.get("DEFAULT", "media_dir"), - config.get("DEFAULT", "library")) http_server = WSGIServer(('', 5000), APP, log=None) server = spawn(http_server.serve_forever) - joinall([watcher, server]) + watcher = LibraryWatcher(config.get("DEFAULT", "media_dir"), + config.get("DEFAULT", "library")) + + def check_for_events(): + """Check for changes in the library.""" + while True: + watcher.check_for_events() + + watcher_routine = spawn(check_for_events) + + joinall([watcher_routine, server]) @@ -126,9 +126,6 @@ class LibraryWatcher(object): register(self.stop) - while True: - self.check_for_events() - def stop(self): """Remove all the watched paths.""" if self.wdd[self.path] > 0: |