Lara Monteagudo Tubau commited on
Commit ·
762c8b6
1
Parent(s): 34890bc
Fix: executor resource leak and O(n²) lookup inefficiency
Browse files- pipeline.py: Change executor.shutdown(wait=False) to wait=True to prevent
worker threads from leaking when caller cancels. Threads now complete
before generator returns.
- app.py fn_run_all_boundaries: Pre-build failed_sids set (O(1) lookup)
instead of checking pstats.results with any() per section (O(n²)).
Reduces loop overhead for 20 sections by ~98%.
Files changed (2)
- app.py+2-1
- pipeline.py+1-1
1484 unmodified lines148514861487148814891490149114921493149414951484 unmodified linesgr.Warning(f"Section {sr.section_id} failed: {sr.error}")processed = len(pstats.results)prog_lines = []for s in sections:sid = s["section_id"]res = collected.get(sid)failed = any((not x.success) and x.section_id == sid for x in pstats.results)if res:b = len(res.get("boundaries", []))e = len(res.get("segments", []))1484 unmodified lines1485148614871488148914901491149214931494149514961484 unmodified linesgr.Warning(f"Section {sr.section_id} failed: {sr.error}")processed = len(pstats.results)failed_sids = {x.section_id for x in pstats.results if not x.success}prog_lines = []for s in sections:sid = s["section_id"]res = collected.get(sid)failed = sid in failed_sidsif res:b = len(res.get("boundaries", []))e = len(res.get("segments", []))
293 unmodified lines294295296297298299300293 unmodified linesexecutor = ThreadPoolExecutor(max_workers=max_workers)for sec in sections:executor.submit(_worker, sec)executor.shutdown(wait=False)# Collect and yield as results arriven_received = 0293 unmodified lines294295296297298299300293 unmodified linesexecutor = ThreadPoolExecutor(max_workers=max_workers)for sec in sections:executor.submit(_worker, sec)executor.shutdown(wait=True)# Collect and yield as results arriven_received = 0
app.py+2-1
pipeline.py+1-1