mirror of
https://github.com/python/cpython.git
synced 2025-10-17 12:18:23 +00:00
bpo-35125: remove inner callback on outer cancellation in asyncio shield (GH-10340)
When the future returned by shield is cancelled, its completion callback of the inner future is not removed. This makes the callback list of inner inner future grow each time a shield is created and cancelled. This change unregisters the callback from the inner future when the outer future is cancelled. https://bugs.python.org/issue35125
This commit is contained in:
parent
f7bda5c572
commit
b35acc5b3a
3 changed files with 19 additions and 3 deletions
|
@ -1777,7 +1777,7 @@ class BaseTaskTests:
|
|||
test_utils.run_briefly(self.loop)
|
||||
self.assertIs(outer.exception(), exc)
|
||||
|
||||
def test_shield_cancel(self):
|
||||
def test_shield_cancel_inner(self):
|
||||
inner = self.new_future(self.loop)
|
||||
outer = asyncio.shield(inner)
|
||||
test_utils.run_briefly(self.loop)
|
||||
|
@ -1785,6 +1785,15 @@ class BaseTaskTests:
|
|||
test_utils.run_briefly(self.loop)
|
||||
self.assertTrue(outer.cancelled())
|
||||
|
||||
def test_shield_cancel_outer(self):
|
||||
inner = self.new_future(self.loop)
|
||||
outer = asyncio.shield(inner)
|
||||
test_utils.run_briefly(self.loop)
|
||||
outer.cancel()
|
||||
test_utils.run_briefly(self.loop)
|
||||
self.assertTrue(outer.cancelled())
|
||||
self.assertEqual(0, 0 if outer._callbacks is None else len(outer._callbacks))
|
||||
|
||||
def test_shield_shortcut(self):
|
||||
fut = self.new_future(self.loop)
|
||||
fut.set_result(42)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue