Last active
May 20, 2021 01:51
-
-
Save rayepeng/d7ed0dcc9613741ac3dd977602aea909 to your computer and use it in GitHub Desktop.
线程池.py #Python #多线程
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from concurrent.futures import ThreadPoolExecutor, as_completed | |
pool = ThreadPoolExecutor(3) | |
task_list = set() | |
targets = [ | |
'http://xxx', | |
'http://xxx', | |
'http://xxx' | |
] | |
for url in targets: | |
task_list.add(pool.submit(requests.get, url)) | |
for future in as_completed(task_list): | |
print(future.result()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment