gh-124958: fix asyncio.TaskGroup and _PyFuture refcycles (#124959)

This commit is contained in:
Thomas Grainger 2024-10-14 16:19:56 +01:00 committed by GitHub
parent 45df264f3f
commit d5dbbf4372
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 147 additions and 15 deletions

View file

@ -659,6 +659,28 @@ class BaseFutureTests:
fut = self._new_future(loop=self.loop)
fut.set_result(Evil())
def test_future_cancelled_result_refcycles(self):
f = self._new_future(loop=self.loop)
f.cancel()
exc = None
try:
f.result()
except asyncio.CancelledError as e:
exc = e
self.assertIsNotNone(exc)
self.assertListEqual(gc.get_referrers(exc), [])
def test_future_cancelled_exception_refcycles(self):
f = self._new_future(loop=self.loop)
f.cancel()
exc = None
try:
f.exception()
except asyncio.CancelledError as e:
exc = e
self.assertIsNotNone(exc)
self.assertListEqual(gc.get_referrers(exc), [])
@unittest.skipUnless(hasattr(futures, '_CFuture'),
'requires the C _asyncio module')