天天看點

python列印堆棧資訊

import logging

import traceback





       
def testPrintStackInfo(self):
        try:
            1 / 0   # 觸發異常
        except BaseException as e:
            msg = traceback.format_exc() # 方式1
            print (msg)
            logging.exception(e)    # 方式2
        finally:
            pass
    ### ---------------------------------------------------------------------------------------------