robust_util.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. __title__ = '鲁棒性工具类'
  5. @Time : 2020/9/30 14:51
  6. @Author : zhengwangeng
  7. @Software: PyCharm
  8. # code is far away from bugs with the god animal protecting
  9. I love animals. They taste delicious.
  10. ┏┓ ┏┓
  11. ┏┛┻━━━┛┻┓
  12. ┃ ☃ ┃
  13. ┃ ┳┛ ┗┳ ┃
  14. ┃ ┻ ┃
  15. ┗━┓ ┏━┛
  16. ┃ ┗━━━┓
  17. ┃ 神兽保佑 ┣┓
  18. ┃ 永无BUG! ┏┛
  19. ┗┓┓┏━┳┓┏┛
  20. ┃┫┫ ┃┫┫
  21. ┗┻┛ ┗┻┛
  22. """
  23. import sys
  24. import traceback
  25. # 异常处理装饰器
  26. def catch_exception(actual_do):
  27. def add_robust(*args, **keyargs):
  28. try:
  29. return actual_do(*args, **keyargs)
  30. except Exception as err:
  31. # print('Error execute: %s' % actual_do.__name__)
  32. info = sys.exc_info()[2].tb_frame.f_back
  33. temp = "exception:filename:{}\tlines:{}\tfuncation:{}\terror:{}"
  34. # print(temp.format(info.f_code.co_filename, info.f_lineno, actual_do.__name__, repr(err)))
  35. traceback.print_exc()
  36. return add_robust