import time from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler, LoggingEventHandler # from config import LOCAL_PATH_TO_WATCHER import os LOCAL_PATH_TO_WATCHER = '/path/to/dir/' class Watcher: def __init__(self): self.observer = Observer() def run(self): event_handler = Event() self.observer.schedule(event_handler, path =LOCAL_PATH_TO_WATCHER, recursive=True) self.observer.start() try: while True: time.sleep(1) except: self.observer.stop() print ("Error") self.observer.join() class Event(LoggingEventHandler): def dispatch(self, event): if event.is_directory: return None elif event.event_type == 'created': return event.src_path
watcher.py
Now i want to initialize a Watcher object and trigger the function in my main file.
from watcher import Watcher def crop(img): # some implementation if __name__ == '__main__': # This will run the pipeline file for the first time. w = Watcher() w.run()
main.py
I want to access the image from watcher object's dispatch function to run crop function in the main file