小编Z. *_*Qui的帖子

python 异步上下文管理器

在 Python Lan 参考文献中。3.4.4,据说__aenter__()并且__aexit__()必须返回awaitables。但是,在示例异步上下文管理器中,这两个方法返回 None:

class AsyncContextManager:
    async def __aenter__(self):
        await log('entering context')

    async def __aexit__(self, exc_type, exc, tb):
        await log('exiting context')
Run Code Online (Sandbox Code Playgroud)

这段代码正确吗?

python asynchronous contextmanager

4
推荐指数
1
解决办法
7474
查看次数

标签 统计

asynchronous ×1

contextmanager ×1

python ×1