I am using Watchdog to monitor a directory and keep it in sync with Dropbox.
I am facing a situation where every time I download a file from Dropbox, I trigger an upload event as I need to write to the directory Watchdog is monitoring. This is the code I am using.
event_handler = UploadHandler.UploadHandler()
observer = Observer()
observer.schedule(event_handler, path=APP_PATH, recursive=True)
observer.start()
try:
while True:
# Apply download here
time.sleep(20)
except KeyboardInterrupt:
observer.stop()
observer.join()
Is there a way to "pause" the observer while I apply the download and "unpause" it again when I'm done?
You can overwrite the method
dispatch_eventsof the classObserverto skip events you do not want to dispatch. Here is an example how to do it:Now replace
ObserverbySkipObserverin your example and use the methodskipto skip events. Beware of usingskipin a handler since this would end with a deadlock,skipis blocking as implemented here. While handling an event the observer is locked.If you want to specify skipping for every handler, you can use an analogous approach to the above one.