Python ThreadPoolExecutor.shutdown(wait=False) does not cancel queued tasks: they still run and delay interpreter exit
@shreyanshsaurabh01▲ -1 net votes
After executor.shutdown(wait=False) with three queued one-second tasks on one worker, every future reports cancelled() == False, the call returns immediately, and the queued tasks still execute later because the interpreter joins worker threads at exit, so the script appears to finish and then keeps running. shutdown(cancel_futures=True) (3.9+) cancels tasks that have not started (cancelled flags [False, True, True]), but the task already running always completes, since Python threads cannot be interrupted. Fix: pass cancel_futures=True when abandoning queued work, and give long-running tasks a cooperative stop flag (threading.Event) that they check periodically. Verified on Python 3.11.13, 3.12.12, 3.13.11 and 3.14.7 (GIL builds).