finally:
loop.close()
+ def test_proper_refcounts(self):
+ # see: https://github.com/python/cpython/issues/126083
+ class Break:
+ def __str__(self):
+ raise RuntimeError("break")
+
+ obj = object()
+ initial_refcount = sys.getrefcount(obj)
+
+ coro = coroutine_function()
+ loop = asyncio.new_event_loop()
+ task = asyncio.Task.__new__(asyncio.Task)
+
+ for _ in range(5):
+ with self.assertRaisesRegex(RuntimeError, 'break'):
+ task.__init__(coro, loop=loop, context=obj, name=Break())
+
+ coro.close()
+ del task
+
+ self.assertEqual(sys.getrefcount(obj), initial_refcount)
+
def add_subclass_tests(cls):
BaseTask = cls.Task
return -1;
}
} else {
- self->task_context = Py_NewRef(context);
+ Py_XSETREF(self->task_context, Py_NewRef(context));
}
Py_CLEAR(self->task_fut_waiter);