enter_async_context(aiofiles.open('data.txt')) # 使用 db_conn 和 file... # 退出时自动关闭文件和数据库连接 push_async_exit(callback) 添加一个异步回调函数,该函数将在退出时被调用: async def cleanup_resource(resource): await resource.close(
An asynchronous context manager, similar to ExitStack, that supports combining both synchronous and asynchronous context managers, as well as having coroutines for cleanup logic. The close() method is not implemented, aclose() must be used instead. enter_async_context(cm) Similar to enter_context...