Skip to content

Commit 7dc850b

Browse files
committed
test_concurrent_futures.test_map_exception: assert no reference cycle from failed future captured in its exception’s traceback
1 parent a123245 commit 7dc850b

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

Lib/test/test_concurrent_futures/executor.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import gc
12
import itertools
23
import threading
34
import time
@@ -55,8 +56,20 @@ def test_map_exception(self):
5556
i = self.executor.map(divmod, [1, 1, 1, 1], [2, 3, 0, 5])
5657
self.assertEqual(i.__next__(), (0, 1))
5758
self.assertEqual(i.__next__(), (0, 1))
58-
with self.assertRaises(ZeroDivisionError):
59-
i.__next__()
59+
60+
error = None
61+
try:
62+
next(i)
63+
except ZeroDivisionError as zero_div_error:
64+
error = zero_div_error
65+
self.assertIsNotNone(
66+
error,
67+
msg="next one should raise a ZeroDivisionError",
68+
)
69+
70+
# a failed future must not be captured in its
71+
# future._exception.__traceback__ to avoid a reference cycle
72+
self.assertFalse(gc.get_referrers(error))
6073

6174
@support.requires_resource('walltime')
6275
def test_map_timeout(self):

0 commit comments

Comments
 (0)