diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-07-09 11:00:23 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-09 11:00:23 (GMT) |
commit | 91b4f7ab7f9a5e0908b91379ee085ae087a76483 (patch) | |
tree | 95b879d778ece59813781818ab19c1e2f8adbb9d /Doc/library/test.rst | |
parent | cf9c41c422de3774862db964fe3153086bad3f61 (diff) | |
download | cpython-91b4f7ab7f9a5e0908b91379ee085ae087a76483.zip cpython-91b4f7ab7f9a5e0908b91379ee085ae087a76483.tar.gz cpython-91b4f7ab7f9a5e0908b91379ee085ae087a76483.tar.bz2 |
bpo-37526: Add support.catch_threading_exception() (GH-14664)
Context manager catching threading.Thread exception using
threading.excepthook.
Diffstat (limited to 'Doc/library/test.rst')
-rw-r--r-- | Doc/library/test.rst | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Doc/library/test.rst b/Doc/library/test.rst index 920c018..7d62a94 100644 --- a/Doc/library/test.rst +++ b/Doc/library/test.rst @@ -1081,6 +1081,39 @@ The :mod:`test.support` module defines the following functions: :exc:`PermissionError` is raised. +.. function:: catch_threading_exception() + + Context manager catching :class:`threading.Thread` exception using + :func:`threading.excepthook`. + + Attributes set when an exception is catched: + + * ``exc_type`` + * ``exc_value`` + * ``exc_traceback`` + * ``thread`` + + See :func:`threading.excepthook` documentation. + + These attributes are deleted at the context manager exit. + + Usage:: + + with support.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) + + .. versionadded:: 3.8 + + .. function:: catch_unraisable_exception() Context manager catching unraisable exception using |