【发布时间】:2018-05-23 09:22:10
【问题描述】:
据我所知,asyncio.test_utils 没有记录在案,因为它是供私人使用的(请参阅此issue)。
不过,我想知道asyncio.test_utils.run_briefly 的剂量。
例如,在这里,你能解释一下吗?
def test_gather_shield(self):
child1 = asyncio.Future(loop=self.loop)
child2 = asyncio.Future(loop=self.loop)
inner1 = asyncio.shield(child1, loop=self.loop)
inner2 = asyncio.shield(child2, loop=self.loop)
parent = asyncio.gather(inner1, inner2, loop=self.loop)
test_utils.run_briefly(self.loop)
parent.cancel()
# This should cancel inner1 and inner2 but bot child1 and child2.
test_utils.run_briefly(self.loop)
self.assertIsInstance(parent.exception(), asyncio.CancelledError)
self.assertTrue(inner1.cancelled())
self.assertTrue(inner2.cancelled())
child1.set_result(1)
child2.set_result(2)
test_utils.run_briefly(self.loop)
【问题讨论】:
标签: python python-3.6 python-asyncio