|
48 | 48 | import subprocess |
49 | 49 | import sys |
50 | 50 | import time |
51 | | -from concurrent.futures import ThreadPoolExecutor |
| 51 | +from concurrent.futures import ThreadPoolExecutor, TimeoutError |
52 | 52 | from datetime import datetime |
53 | 53 | from typing import Dict, List, Optional |
54 | 54 | from urllib.parse import urlparse |
@@ -342,8 +342,18 @@ def fetch_ardupilot_generated_data(site_mapping: Dict, base_url: str, sub_url: s |
342 | 342 | targetfiles.append(targetfile) |
343 | 343 | names.append(f"{value}_{document_name}") |
344 | 344 |
|
345 | | - with ThreadPoolExecutor() as executor: |
346 | | - executor.map(fetch_and_rename, urls, targetfiles, names, timeout=5*60) |
| 345 | + with ThreadPoolExecutor(max_workers=4) as executor: # Limit concurrent downloads |
| 346 | + tasks = [] |
| 347 | + for url, target, name in zip(urls, targetfiles, names): |
| 348 | + task = executor.submit(fetch_and_rename, url, target, name) |
| 349 | + tasks.append(task) |
| 350 | + |
| 351 | + # Wait for all downloads to complete |
| 352 | + for task in tasks: |
| 353 | + try: |
| 354 | + task.result(timeout=5*60) |
| 355 | + except (TimeoutError, OSError, requests.RequestException) as e: |
| 356 | + error(f"Download failed: {e}") |
347 | 357 |
|
348 | 358 |
|
349 | 359 | def build_one(wiki, fast): |
|
0 commit comments