summaryrefslogtreecommitdiffstats
path: root/Doc/library
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/sys.rst6
-rw-r--r--Doc/library/threading.rst30
2 files changed, 35 insertions, 1 deletions
diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst
index 51a208e..74aa271 100644
--- a/Doc/library/sys.rst
+++ b/Doc/library/sys.rst
@@ -298,7 +298,11 @@ always available.
before the program exits. The handling of such top-level exceptions can be
customized by assigning another three-argument function to ``sys.excepthook``.
- See also :func:`unraisablehook` which handles unraisable exceptions.
+ .. seealso::
+
+ The :func:`sys.unraisablehook` function handles unraisable exceptions
+ and the :func:`threading.excepthook` function handles exception raised
+ by :func:`threading.Thread.run`.
.. data:: __breakpointhook__
diff --git a/Doc/library/threading.rst b/Doc/library/threading.rst
index 1df512f..ffe6d04 100644
--- a/Doc/library/threading.rst
+++ b/Doc/library/threading.rst
@@ -38,6 +38,32 @@ This module defines the following functions:
returned.
+.. function:: excepthook(args, /)
+
+ Handle uncaught exception raised by :func:`Thread.run`.
+
+ The *args* argument has the following attributes:
+
+ * *exc_type*: Exception type.
+ * *exc_value*: Exception value, can be ``None``.
+ * *exc_traceback*: Exception traceback, can be ``None``.
+ * *thread*: Thread which raised the exception, can be ``None``.
+
+ If *exc_type* is :exc:`SystemExit`, the exception is silently ignored.
+ Otherwise, the exception is printed out on :data:`sys.stderr`.
+
+ If this function raises an exception, :func:`sys.excepthook` is called to
+ handle it.
+
+ :func:`threading.excepthook` can be overridden to control how uncaught
+ exceptions raised by :func:`Thread.run` are handled.
+
+ .. seealso::
+ :func:`sys.excepthook` handles uncaught exceptions.
+
+ .. versionadded:: 3.8
+
+
.. function:: get_ident()
Return the 'thread identifier' of the current thread. This is a nonzero
@@ -191,6 +217,10 @@ called is terminated.
A thread has a name. The name can be passed to the constructor, and read or
changed through the :attr:`~Thread.name` attribute.
+If the :meth:`~Thread.run` method raises an exception,
+:func:`threading.excepthook` is called to handle it. By default,
+:func:`threading.excepthook` ignores silently :exc:`SystemExit`.
+
A thread can be flagged as a "daemon thread". The significance of this flag is
that the entire Python program exits when only daemon threads are left. The
initial value is inherited from the creating thread. The flag can be set