如何使用python处理1000个请求的并行请求?

时间:2019-07-08 08:26:07

标签: python loops request python-requests

如何使用python进行并行请求?

到目前为止,我的代码:

x = ("address")
x.signin(signin.request())
# this code signs in the user and generate the response how to do a parallel response. 

查看了这些内容,但不知道在哪里使用

import asyncio
import requests

 async def main():
     loop = asyncio.get_event_loop()
     futures = [
        loop.run_in_executor(
            None, 
            requests.get, 
            'http://example.org/'
        )
        for i in range(20)
    ]
    for response in await asyncio.gather(*futures):
        pass

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

还查看了此线程:
What is the fastest way to send 100,000 HTTP requests in Python?

0 个答案:

没有答案