def watch_config_changes(config_path, queues, nuimo_apps, processes, ha_api_url, ble_adapter_name):
class ModificationHandler(pyinotify.ProcessEvent):
def process_IN_CLOSE_WRITE(self, event):
if hasattr(event, 'pathname') and event.pathname == config_path:
logger.info("Config file was changed, reloading it...")
update_from_config_file(config_path, queues, nuimo_apps, processes, ha_api_url, ble_adapter_name)
handler = ModificationHandler()
watch_manager = pyinotify.WatchManager()
notifier = pyinotify.Notifier(watch_manager, handler)
# IN_CLOSE_WRITE is fired when the file was closed after modification
# in opposite to IN_MODIFY which is called for each partial write
watch_manager.add_watch(config_path, pyinotify.IN_CLOSE_WRITE)
logger.info("Listening to changes of: %s", config_path)
notifier.loop()
logger.info("Stopped listening to changes of: %s", config_path)
评论列表
文章目录