locks_test.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:projects-2017-2 作者: ncss 项目源码 文件源码
def test_context_manager_contended(self):
        sem = locks.Semaphore()
        history = []

        @gen.coroutine
        def f(index):
            with (yield sem.acquire()):
                history.append('acquired %d' % index)
                yield gen.sleep(0.01)
                history.append('release %d' % index)

        yield [f(i) for i in range(2)]

        expected_history = []
        for i in range(2):
            expected_history.extend(['acquired %d' % i, 'release %d' % i])

        self.assertEqual(expected_history, history)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号