mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
bpo-37261: Fix support.catch_unraisable_exception() (GH-14052)
The __exit__() method of test.support.catch_unraisable_exception context manager now ignores unraisable exception raised when clearing self.unraisable attribute.
This commit is contained in:
parent
63ab4ba07b
commit
6d22cc8e90
3 changed files with 35 additions and 2 deletions
|
@ -1086,6 +1086,18 @@ The :mod:`test.support` module defines the following functions:
|
|||
Context manager catching unraisable exception using
|
||||
:func:`sys.unraisablehook`.
|
||||
|
||||
If the *object* attribute of the unraisable hook is set and the object is
|
||||
being finalized, the object is resurrected because the context manager
|
||||
stores a strong reference to it (``cm.unraisable.object``).
|
||||
|
||||
Storing the exception value (``cm.unraisable.exc_value``) creates a
|
||||
reference cycle. The reference cycle is broken explicitly when the context
|
||||
manager exits.
|
||||
|
||||
Exiting the context manager clears the stored unraisable exception. It can
|
||||
trigger a new unraisable exception (ex: the resurrected object is finalized
|
||||
again and raises the same exception): it is silently ignored in this case.
|
||||
|
||||
Usage::
|
||||
|
||||
with support.catch_unraisable_exception() as cm:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue