Skip to content

Instantly share code, notes, and snippets.

@rayepeng
Last active May 20, 2021 01:51
Show Gist options
  • Save rayepeng/d7ed0dcc9613741ac3dd977602aea909 to your computer and use it in GitHub Desktop.
Save rayepeng/d7ed0dcc9613741ac3dd977602aea909 to your computer and use it in GitHub Desktop.
线程池.py #Python #多线程
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