python之异常捕获&清除的打印报错行
python代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
import time import traceback from threading import Thread def fun1(): fun1_1() def fun2(): t = Thread(target=fun2_1()) t.start() def fun1_1(): print('fun1_1') def fun2_1(): 1 / 0 def main(): while True: try: time.sleep(1) fun1() fun2() except Exception: traceback.print_exc() if __name__ == '__main__': main()
效果图:
-----------------------------------------------------------------------------------------------------------------------------------------