async def _register_local_data_watcher(self): async def ping(event, interval): while True: await asyncio.sleep(interval) if not self.watched_running_games: if not event.is_set(): event.set() parse_local_data_event = asyncio.Event() FileWatcher(self.CONFIG_PATH, parse_local_data_event, interval=1) FileWatcher(self.PRODUCT_DB_PATH, parse_local_data_event, interval=2.5) asyncio.create_task(ping(parse_local_data_event, 30)) while True: await parse_local_data_event.wait() refreshed_games = self._parse_local_data() if not self.notifications_enabled: self._update_statuses(refreshed_games, self.installed_games) self.installed_games = refreshed_games parse_local_data_event.clear()
async def _register_local_data_watcher(self): parse_local_data_event = asyncio.Event() FileWatcher(self.CONFIG_PATH, parse_local_data_event, interval=1) FileWatcher(self.PRODUCT_DB_PATH, parse_local_data_event, interval=2.5) parse_local_data_event.set() while True: await parse_local_data_event.wait() if not self._load_local_files(): parse_local_data_event.clear() continue if self.is_installed != self.database_parser.battlenet_present: self.refresh() self._games_provider.parse_local_battlenet_games(self.database_parser.games, self.config_parser.games) refreshed_games = self.get_installed_games() self._update_statuses(refreshed_games, self.installed_games_cache) self.installed_games_cache = refreshed_games parse_local_data_event.clear()
import time from watcher import FileWatcher def on_create(): print('created file') def on_modified(): print('modified file') watcher = FileWatcher('.', '*.jpg', on_create, on_modified) watcher.start() try: while True: time.sleep(1) except KeyboardInterrupt: watcher.stop()
def main(path, patterns): print(f"Watching: {path} for patterns {patterns}") patterns = [pattern.strip() for pattern in patterns.split(",")] FileWatcher(path, patterns).run()