Bubbles30 commited on
Commit
df88c95
·
verified ·
1 Parent(s): 3965886

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -10
app.py CHANGED
@@ -317,21 +317,19 @@ def handle_batch(workbook_path, fmt, w, h):
317
  tasks.append((code, url, dl_path, suf))
318
 
319
  # Download with tracking
320
- futures = {}
321
  with ThreadPoolExecutor(max_workers=min(32, CPU_CORES*2)) as ex:
322
- futures = []
323
  for code, url, dl_path, suf in tasks:
324
- futures.append(ex.submit(
325
- download_image_fast, url, dl_path, fail_log, code, suf
326
- ))
327
- for fut in as_completed(futures):
328
- success = fut.result()
329
- # failures logged inside download_image_fast already
330
 
331
- code, suf = futures[fut]
 
 
 
332
  if not success:
333
  log_failure(fail_log, f"{code}{suf}: download failed")
334
-
335
  processed = []
336
  for code, url, dl_path, suf in tasks:
337
  if not os.path.exists(dl_path): continue
 
317
  tasks.append((code, url, dl_path, suf))
318
 
319
  # Download with tracking
320
+ future_to_task = {}
321
  with ThreadPoolExecutor(max_workers=min(32, CPU_CORES*2)) as ex:
322
+ # submit each download job *and* remember its (code, suf)
323
  for code, url, dl_path, suf in tasks:
324
+ fut = ex.submit(download_image_fast, url, dl_path, fail_log, code, suf)
325
+ future_to_task[fut] = (code, suf)
 
 
 
 
326
 
327
+ # as each future finishes, look up its metadata
328
+ for fut in as_completed(future_to_task):
329
+ success = fut.result()
330
+ code, suf = future_to_task[fut]
331
  if not success:
332
  log_failure(fail_log, f"{code}{suf}: download failed")
 
333
  processed = []
334
  for code, url, dl_path, suf in tasks:
335
  if not os.path.exists(dl_path): continue