Fabric是Python编写的自动化运维工具,使用fabric批量去机器上面执行shell脚本的时候,可能会遇到机器故障等情况,造成执行中断,那么能否忽略或者说爆出异常之后继续执行呢?那就需要fabric的异常处理,具体实现参见下面
import logging
try:
1/0
except Exception as e:
logging.exception(e)
错误异常打印如下:
ERROR:root:division by zero
Traceback (most recent call last):
File "/home/padraic/Dropbox/python/py3/size.py", line 105, in <module>
1/0
ZeroDivisionError: division by zero
Process finished with exit code 0