mirror of
https://github.com/python/cpython.git
synced 2025-10-01 04:42:10 +00:00
[3.12] Docs: emphasise warning and add accurate markups for sys.unraisablehook (GH-108105) (#108109)
Docs: emphasise warning and add accurate markups for sys.unraisablehook (GH-108105)
(cherry picked from commit cc58ec9724
)
Co-authored-by: Erlend E. Aasland <erlend@python.org>
This commit is contained in:
parent
2b8e0207cb
commit
af6e5fa718
1 changed files with 21 additions and 17 deletions
|
@ -1811,35 +1811,39 @@ always available.
|
||||||
|
|
||||||
The *unraisable* argument has the following attributes:
|
The *unraisable* argument has the following attributes:
|
||||||
|
|
||||||
* *exc_type*: Exception type.
|
* :attr:`!exc_type`: Exception type.
|
||||||
* *exc_value*: Exception value, can be ``None``.
|
* :attr:`!exc_value`: Exception value, can be ``None``.
|
||||||
* *exc_traceback*: Exception traceback, can be ``None``.
|
* :attr:`!exc_traceback`: Exception traceback, can be ``None``.
|
||||||
* *err_msg*: Error message, can be ``None``.
|
* :attr:`!err_msg`: Error message, can be ``None``.
|
||||||
* *object*: Object causing the exception, can be ``None``.
|
* :attr:`!object`: Object causing the exception, can be ``None``.
|
||||||
|
|
||||||
The default hook formats *err_msg* and *object* as:
|
The default hook formats :attr:`!err_msg` and :attr:`!object` as:
|
||||||
``f'{err_msg}: {object!r}'``; use "Exception ignored in" error message
|
``f'{err_msg}: {object!r}'``; use "Exception ignored in" error message
|
||||||
if *err_msg* is ``None``.
|
if :attr:`!err_msg` is ``None``.
|
||||||
|
|
||||||
:func:`sys.unraisablehook` can be overridden to control how unraisable
|
:func:`sys.unraisablehook` can be overridden to control how unraisable
|
||||||
exceptions are handled.
|
exceptions are handled.
|
||||||
|
|
||||||
Storing *exc_value* using a custom hook can create a reference cycle. It
|
.. seealso::
|
||||||
should be cleared explicitly to break the reference cycle when the
|
|
||||||
exception is no longer needed.
|
|
||||||
|
|
||||||
Storing *object* using a custom hook can resurrect it if it is set to an
|
:func:`excepthook` which handles uncaught exceptions.
|
||||||
object which is being finalized. Avoid storing *object* after the custom
|
|
||||||
hook completes to avoid resurrecting objects.
|
|
||||||
|
|
||||||
See also :func:`excepthook` which handles uncaught exceptions.
|
.. warning::
|
||||||
|
|
||||||
|
Storing :attr:`!exc_value` using a custom hook can create a reference cycle.
|
||||||
|
It should be cleared explicitly to break the reference cycle when the
|
||||||
|
exception is no longer needed.
|
||||||
|
|
||||||
|
Storing :attr:`!object` using a custom hook can resurrect it if it is set to an
|
||||||
|
object which is being finalized. Avoid storing :attr:`!object` after the custom
|
||||||
|
hook completes to avoid resurrecting objects.
|
||||||
|
|
||||||
.. audit-event:: sys.unraisablehook hook,unraisable sys.unraisablehook
|
.. audit-event:: sys.unraisablehook hook,unraisable sys.unraisablehook
|
||||||
|
|
||||||
Raise an auditing event ``sys.unraisablehook`` with arguments
|
Raise an auditing event ``sys.unraisablehook`` with arguments
|
||||||
``hook``, ``unraisable`` when an exception that cannot be handled occurs.
|
*hook*, *unraisable* when an exception that cannot be handled occurs.
|
||||||
The ``unraisable`` object is the same as what will be passed to the hook.
|
The *unraisable* object is the same as what will be passed to the hook.
|
||||||
If no hook has been set, ``hook`` may be ``None``.
|
If no hook has been set, *hook* may be ``None``.
|
||||||
|
|
||||||
.. versionadded:: 3.8
|
.. versionadded:: 3.8
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue