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
    ### ---------------------------------------------------------------------------------------------


你可能感兴趣的:(python)