
881
21
장
비동기 프로그래밍
to_do_iter = asyncio.as_completed(to_do) ❹
if not verbose:
to_do_iter = tqdm.tqdm(to_do_iter, total=len(cc_list)) ❺
error: httpx.HTTPError | None = None ❻
for coro in to_do_iter: ❼
try:
status = await coro ❽
except httpx.HTTPStatusError as exc:
error_msg = ‘HTTP error {resp.status_code} - {resp.reason_phrase}’
error_msg = error_msg.format(resp=exc.response)
error = exc ❾
except httpx.RequestError as exc:
error_msg = f’{exc} {type(exc)}’.strip()
error = exc ❿
except KeyboardInterrupt:
break
if error:
status = DownloadStatus.ERROR ⓫
if verbose:
url = str(error.request.url) ⓬
cc = Path(url).stem.upper() ⓭
print(f’{cc} error: {error_msg}’) ...