import asyncio
async def fetch_data(url):
# 模拟网络请求
await asyncio.sleep(1)
return f"Data from {url}"
async def main():
tasks = [
fetch_data("https://api.example.com/1"),
fetch_data("https://api.example.com/2")
]
results = await asyncio.gather(*tasks)
print(results)
asyncio.run(main())