python之異常捕獲&清除的列印報錯行

發表於2024-06-20

python程式碼:

python之異常捕獲&清除的列印報錯行
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()
View Code

效果圖:

相關文章