def monitor_directory(directory):
"""Starts monitoring the specified directory in a background thread. File events
will be passed to the `CompletedJobInfoEventHandler`.
Arguments:
directory: the directory to monitor.
"""
observer = Observer()
logging.info("Getting ready to monitor directory {}".format(directory))
event_handler = CompletedJobInfoEventHandler()
observer.schedule(event_handler, directory, recursive=True)
def stop_monitoring(*args, **kwargs):
"""Tells watchdog to stop watching the directory when the newly processed run
was discovered."""
logging.info("Halting monitoring on directory because run was discovered.")
observer.stop()
observer.join()
pub.subscribe(stop_monitoring, SettingsDialog.settings_closed_topic)
pub.subscribe(stop_monitoring, DirectoryMonitorTopics.new_run_observed)
pub.subscribe(stop_monitoring, DirectoryMonitorTopics.shut_down_directory_monitor)
observer.start()
评论列表
文章目录