同步库与协程的共同使用

 

 

# coding: utf-8
# @Time    : 2022-05-17 21:53
# @Author  : AngDH
import asyncio

import requests


async def main():
    loop = asyncio.get_event_loop()
    future1 = loop.run_in_executor(None, requests.get, "http://www.baidu.com")
    future2 = loop.run_in_executor(None, requests.get, "http://www.taobao.com")

    response1 = await future1
    response2 = await future2

    print(response1.status_code,"111111")
    print(response2.status_code,"22222")



asyncio.run(main())

 

posted @ 2022-05-17 22:06  AngDH  阅读(22)  评论(0编辑  收藏  举报