Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Filesystem events monitoring with Python [watcher.py]
import sys
import time
from watchdog.observers import Observer
from .events import ImagesEventHandler
class ImagesWatcher:
def __init__(self, src_path):
self.__src_path = src_path
self.__event_handler = ImagesEventHandler()
self.__event_observer = Observer()
def run(self):
self.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
self.stop()
def start(self):
self.__schedule()
self.__event_observer.start()
def stop(self):
self.__event_observer.stop()
self.__event_observer.join()
def __schedule(self):
self.__event_observer.schedule(
self.__event_handler,
self.__src_path,
recursive=True
)
if __name__ == "__main__":
src_path = sys.argv[1] if len(sys.argv) > 1 else '.'
ImagesWatcher(src_path).run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.