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


Python test.support.threading_helper.catch_threading_exception用法及代碼示例

用法:

test.support.threading_helper.catch_threading_exception()

上下文管理器使用 threading.excepthook() 捕獲 threading.Thread 異常。

捕獲異常時設置的屬性:

  • exc_type
  • exc_value
  • exc_traceback
  • thread

請參閱threading.excepthook() 文檔。

這些屬性在上下文管理器出口處被刪除。

用法:

with threading_helper.catch_threading_exception() as cm:
    # code spawning a thread which raises an exception
    ...

    # check the thread exception, use cm attributes:
    # exc_type, exc_value, exc_traceback, thread
    ...

# exc_type, exc_value, exc_traceback, thread attributes of cm no longer
# exists at this point
# (to avoid reference cycles)

3.8 版中的新函數。

相關用法


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