1. from concurrent.futures import ThreadPoolExecutor
    2. import time
    3. import requests
    4. import urllib3
    5. urllib3.disable_warnings()
    6. # 定义一个准备作为线程任务的函数
    7. def action():
    8. my_sum = 0
    9. requests.get('https://www.baidu.com/', verify=False)
    10. return my_sum
    11. # 创建一个包含100条线程的线程池
    12. pool = ThreadPoolExecutor(max_workers=100)
    13. start_time = time.perf_counter()
    14. for i in range(50):
    15. # 创建线程池
    16. pool.submit(action)
    17. print(i)
    18. print('运行时长:', time.perf_counter()-start_time)
    19. # 关闭线程池
    20. pool.shutdown()

    实测50个请求不到0.1秒,对于python而言挺好的了