def watch_files(paths, mask): """ Vigila los ficheros de path y encola en queue los eventos producidos. """ watcher = WatchManager() mask = (EventsCodes.ALL_FLAGS.get('IN_MODIFY', 0)) @asyncio.coroutine def send_event(event): """Encola un evento en la cola.""" yield from event_queue.put(event) notifier = ThreadedNotifier( watcher, lambda e: asyncio.get_event_loop().call_soon_threadsafe( asyncio.async, send_event(e))) for path in paths: watcher.add_watch(path, mask, rec=True) while True: notifier.process_events() event_present = yield from asyncio.get_event_loop().run_in_executor( None, notifier.check_events) if event_present: notifier.read_events()
def run(self): logging.info( 'Thead Watcher' ) wm = WatchManager() notifier = ThreadedNotifier(wm, PTmp()) notifier.start() wdd = wm.add_watch( account_dir, 4095, rec=True, auto_add=True) #ALL_EVENTS=>4095 logging.info('Add watch on folder ' + account_dir); while True: try: notifier.process_events() if notifier.check_events(): notifier.read_events() except KeyboardInterrupt: break