當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python test.support.catch_unraisable_exception用法及代碼示例

用法:

test.support.catch_unraisable_exception()

上下文管理器使用 sys.unraisablehook() 捕獲無法引發的異常。

存儲異常值 (cm.unraisable.exc_value) 會創建一個引用循環。當上下文管理器退出時,引用循環被顯式破壞。

如果將對象設置為正在完成的對象,則存儲對象 (cm.unraisable.object) 可以使其複活。退出上下文管理器會清除存儲的對象。

用法:

with support.catch_unraisable_exception() as cm:
    # code creating an "unraisable exception"
    ...

    # check the unraisable exception: use cm.unraisable
    ...

# cm.unraisable attribute no longer exists at this point
# (to break a reference cycle)

3.8 版中的新函數。

相關用法


注:本文由純淨天空篩選整理自python.org大神的英文原創作品 test.support.catch_unraisable_exception。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。