asyncio.test_utils.run_briefly 到底是做什么的?

What does asyncio.test_utils.run_briefly exactly do?

据我所知,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)

助手进行单事件循环迭代。 它使 asyncio 有机会执行所有未决活动,例如 loop.call_soon()

大致相当于loop.run_until_complete(asyncio.sleep(0))