mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
bpo-31787: Prevent refleaks when calling __init__() more than once (GH-3995)
This commit is contained in:
parent
aec7532ed3
commit
d019bc8319
13 changed files with 105 additions and 19 deletions
|
@ -2373,6 +2373,20 @@ class CTask_CFuture_Tests(BaseTaskTests, SetMethodsTest,
|
|||
Task = getattr(tasks, '_CTask', None)
|
||||
Future = getattr(futures, '_CFuture', None)
|
||||
|
||||
@support.refcount_test
|
||||
def test_refleaks_in_task___init__(self):
|
||||
gettotalrefcount = support.get_attribute(sys, 'gettotalrefcount')
|
||||
@asyncio.coroutine
|
||||
def coro():
|
||||
pass
|
||||
task = self.new_task(self.loop, coro())
|
||||
self.loop.run_until_complete(task)
|
||||
refs_before = gettotalrefcount()
|
||||
for i in range(100):
|
||||
task.__init__(coro(), loop=self.loop)
|
||||
self.loop.run_until_complete(task)
|
||||
self.assertAlmostEqual(gettotalrefcount() - refs_before, 0, delta=10)
|
||||
|
||||
|
||||
@unittest.skipUnless(hasattr(futures, '_CFuture') and
|
||||
hasattr(tasks, '_CTask'),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue