Python 異常後,啟動啟動debug調試

來源:互聯網
上載者:User

標籤:err   修改   公眾   default   tde   exce   ges   gpo   ace   

這裡需要修改python在異常發生後的處理流程 sys.excepthook 是python系統的異常處理器,重寫一個自訂處理器,並在列印異常資訊後,啟動pdb。 
import sysdef info(type, value, tb):    # 異常類型    # 異常值    # 調用棧    if hasattr(sys, ‘ps1‘) or not sys.stderr.isatty():        # we are in interactive mode or we don‘t have a tty-like        # device, so we call the default hook        sys.__excepthook__(type, value, tb)    else:        import traceback, pdb        # we are NOT in interactive mode, print the exception...        traceback.print_exception(type, value, tb)        print        # ...then start the debugger in post-mortem mode.        pdb.post_mortem(tb)sys.excepthook = info

 

只要在代碼裡,開始import 這個自訂debug module,就可以修改掉系統預設的異常處理過程  __excepthook__ 
----------------------------
關注公眾號號:
挖金礦工:goldminer1024
為您的量化投資理想插上翅膀

Python 異常後,啟動啟動debug調試

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.