sync from Atlas
This commit is contained in:
3
20-executors/getflags/.gitignore
vendored
3
20-executors/getflags/.gitignore
vendored
@@ -1 +1,2 @@
|
||||
flags/
|
||||
flags/
|
||||
downloaded/
|
||||
|
||||
@@ -20,7 +20,7 @@ Sample run::
|
||||
|
||||
# tag::FLAGS2_THREADPOOL[]
|
||||
from collections import Counter
|
||||
from concurrent import futures
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
|
||||
import httpx
|
||||
import tqdm # type: ignore
|
||||
@@ -37,13 +37,13 @@ def download_many(cc_list: list[str],
|
||||
verbose: bool,
|
||||
concur_req: int) -> Counter[DownloadStatus]:
|
||||
counter: Counter[DownloadStatus] = Counter()
|
||||
with futures.ThreadPoolExecutor(max_workers=concur_req) as executor: # <4>
|
||||
with ThreadPoolExecutor(max_workers=concur_req) as executor: # <4>
|
||||
to_do_map = {} # <5>
|
||||
for cc in sorted(cc_list): # <6>
|
||||
future = executor.submit(download_one, cc,
|
||||
base_url, verbose) # <7>
|
||||
to_do_map[future] = cc # <8>
|
||||
done_iter = futures.as_completed(to_do_map) # <9>
|
||||
done_iter = as_completed(to_do_map) # <9>
|
||||
if not verbose:
|
||||
done_iter = tqdm.tqdm(done_iter, total=len(cc_list)) # <10>
|
||||
for future in done_iter: # <11>
|
||||
@@ -52,7 +52,7 @@ def download_many(cc_list: list[str],
|
||||
except httpx.HTTPStatusError as exc: # <13>
|
||||
error_msg = 'HTTP error {resp.status_code} - {resp.reason_phrase}'
|
||||
error_msg = error_msg.format(resp=exc.response)
|
||||
except httpx.RequestError as exc: # <15>
|
||||
except httpx.RequestError as exc:
|
||||
error_msg = f'{exc} {type(exc)}'.strip()
|
||||
except KeyboardInterrupt:
|
||||
break
|
||||
@@ -63,7 +63,7 @@ def download_many(cc_list: list[str],
|
||||
status = DownloadStatus.ERROR
|
||||
counter[status] += 1
|
||||
if verbose and error_msg:
|
||||
cc = to_do_map[future] # <16>
|
||||
cc = to_do_map[future] # <14>
|
||||
print(f'{cc} error: {error_msg}')
|
||||
|
||||
return counter
|
||||
|
||||
Reference in New Issue
Block a user