Closed ucharles closed 6 months ago
# 병렬 처리를 위한 ThreadPoolExecutor 사용
# max_workers는 동시에 실행할 스레드 수, 최대 5개
with ThreadPoolExecutor(max_workers=5) as executor:
future_to_url = {
# download_image 함수를 실행하고 결과를 future에 저장
executor.submit(download_image, url, filename): url
for url, filename in download_tasks
}
for future in as_completed(future_to_url):
url = future_to_url[future]
try:
path = future.result()
if path:
result.append(path)
logging.info(f"{url} downloaded to {path}")
except Exception as exc:
print(f"{url} generated an exception: {exc}")
문제
해결책 (w. ChatGPT)