@@ -224,12 +224,15 @@ def _run_parallel(
224224
225225 proc = "process" if jobs == 1 else "processes"
226226 print (f"Spawning { jobs } worker { proc } ..." , flush = True )
227- with ProcessPoolExecutor (max_workers = jobs , mp_context = ctx ) as ex :
228- futures = {
229- ex .submit (process_one , p , sn , out_dir , config ): (idx , p .name )
230- for idx , (p , sn ) in enumerate (zip (input_paths , safe_names ), 1 )
231- }
232227
228+ ex = ProcessPoolExecutor (max_workers = jobs , mp_context = ctx )
229+ futures = {
230+ ex .submit (process_one , p , sn , out_dir , config ): (idx , p .name )
231+ for idx , (p , sn ) in enumerate (zip (input_paths , safe_names ), 1 )
232+ }
233+
234+ interrupted = False
235+ try :
233236 for fut in as_completed (futures ):
234237 idx , name = futures [fut ]
235238 try :
@@ -242,6 +245,14 @@ def _run_parallel(
242245 flush = True ,
243246 )
244247 errors .append ((idx , name , exc ))
248+ except KeyboardInterrupt :
249+ interrupted = True
250+ print ("\n Interrupted by user. Killing workers..." , flush = True )
251+ ex .kill_workers ()
252+ print ("Shutdown complete." , flush = True )
253+ finally :
254+ if not interrupted :
255+ ex .shutdown (wait = True )
245256
246257 if errors :
247258 failures = "\n " .join (
0 commit comments