异步

更新时间: 2022-10-17 15:17:27

新版SDK异步

新版SDK 支持异步请求 async def 定义异步方法通过await client.{方法名}_async()调用SDK异步方法。

import asyncio

from alibabacloud_ecs20140526.models import DescribeImagesRequest
from alibabacloud_ecs20140526.client import Client
from alibabacloud_tea_openapi.models import Config

'''云服务器示例'''

async def main():
    config = Config(
        access_key_id='<ACCESS-KEY-ID>',
        access_key_secret='<ACCESS-KEY-SECRET>',
        region_id='cn-hangzhou'
    )
    client = Client(config)
    request = DescribeImagesRequest(image_id='<image-id>')
    
    response = await client.describe_images_async(request)
    print(response)
    return response


loop = asyncio.get_event_loop()
loop.run_until_complete(main())
阿里云首页 阿里云SDK 相关技术圈