异步看门狗
wcpan.watchdog的Python项目详细描述
在wcpan.watchdog在
使用asyncio构建的异步看门狗实用程序。在
安装
pip install wcpan.watchdog
命令行用法
您可以简单地使用主模块,如下所示:
^{pr2}$它将为每个更改的文件重新启动命令(如果它仍在运行)。在
库的使用
也可以在代码中使用:
importasyncioimportsignalfromwcpan.watchdog.watcherimportWatcherasyncdefauto_rerun():path='the path you want to observe'# Setup how to stop the watcher.# In this example I use SIGINT to set the Event.loop=asyncio.get_running_loop()stop_event=asyncio.Event()loop.add_signal_handler(signal.SIGINT,lambda:stop_event.set())asyncwithWatcher()aswatcher:# This will not stop until stop_event is set.asyncforchangesinwatcher(path,stop_event=stop_event):# Changes contains changed information.
- 项目
标签: