diff options
Diffstat (limited to 'Lib')
| -rw-r--r-- | Lib/test/support/__init__.py | 15 | ||||
| -rw-r--r-- | Lib/test/test_io.py | 6 |
2 files changed, 8 insertions, 13 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 174e0456dc..7c0efc783e 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -3040,17 +3040,13 @@ class catch_unraisable_exception: """ Context manager catching unraisable exception using 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. + Storing the object (cm.unraisable.object) can resurrect it if it is set to + an object which is being finalized. Exiting the context manager clears the + stored object. Usage: @@ -3080,10 +3076,5 @@ class catch_unraisable_exception: return self def __exit__(self, *exc_info): - # Clear the unraisable exception to explicitly break a reference cycle. - # It can call _hook() again: ignore the new unraisable exception in - # this case. - self.unraisable = None - sys.unraisablehook = self._old_hook del self.unraisable diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 55686d7439..fc474c9905 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -2072,8 +2072,12 @@ class BufferedRWPairTest(unittest.TestCase): writer.close = lambda: None writer = None + # Ignore BufferedWriter (of the BufferedRWPair) unraisable exception with support.catch_unraisable_exception(): - pair = None + # Ignore BufferedRWPair unraisable exception + with support.catch_unraisable_exception(): + pair = None + support.gc_collect() support.gc_collect() def test_reader_writer_close_error_on_close(self): |
