__main__.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:senic-hub 作者: getsenic 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号