-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathio-bound.py
More file actions
26 lines (20 loc) · 773 Bytes
/
io-bound.py
File metadata and controls
26 lines (20 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import concurrent.futures
from urllib.request import Request, urlopen
links = open('res.txt', encoding='utf8').read().split('\n')
def get_respond(url):
request = Request(
url,
headers={'User-Agent': 'Mozilla/5.0 (Windows NT 9.0; Win65; x64; rv:97.0) Gecko/20105107 Firefox/92.0'},
)
resp = urlopen(request, timeout=5)
return resp.code
with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor:
future_to_url = {executor.submit(get_respond, url): url for url in links}
for future in concurrent.futures.as_completed(future_to_url):
url = future_to_url[future]
try:
code = future.result()
except Exception as exc:
print(url, exc)
else:
print(code)