You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DeviceThreadPool shutdown leaves queued futures pending and permits work after close #3927
With one CPU worker, submit a blocking first task and a second queued task, start shutdown(wait=True) on another thread, then release the first task. On the current code, shutdown returns and joins the worker, the first future resolves, but the second future remains pending forever and pool._inflight['cpu'] stays at 1. This was reproduced on CPU:
_DeviceWorker.stop sets _stop immediately and enqueues a sentinel, but _DeviceWorker._run loops only while _stop is unset. DeviceThreadPool.shutdown calls stop() before draining the queue, so the worker exits after the current task and never consumes queued tasks or resolves their futures. A caller waiting on f2.result() or pool.wait() can hang indefinitely.
The same lifecycle boundary is not enforced on submission: submit / submit_serial do not reject work after _stop_event is set, and lazy worker selection can start a new thread after shutdown. This should be fixed with the queue-drain/stop behavior as one shutdown contract.
Expected
shutdown(wait=True) should finish previously accepted tasks (or explicitly cancel and resolve their futures) and leave accurate in-flight counters. Submissions after shutdown starts should be rejected. Add a deterministic blocked-first-task/queued-second-task regression test.
Additional GIL=0 shutdown deadlock on main at 221cd564 (separate from the queued-future behavior above).
shutdown(wait=True) sets _stop_event and _gc_event, then joins the janitor before stopping workers. The janitor can instead be blocked in _auto_gc_disable_cv.wait() inside no_auto_gc(). Shutdown never notifies that condition, so its join waits until the context exits; if the context remains open, it can wait indefinitely.
Reproduced on Python 3.14.10 with PYTHON_GIL=0, sys._is_gil_enabled() == False, Torch 2.15 CUDA, one GPU:
p=DeviceThreadPool(devices=[torch.device('cuda:0')], include_cpu=False,
empty_cache_every_n=1, gc_debounce_seconds=0,
workers={'cuda:0': 1})
entered=threading.Event()
wait=p._auto_gc_disable_cv.waitp._auto_gc_disable_cv.wait=lambda*a, **kw: (entered.set(), wait(*a, **kw))[1]
withp.no_auto_gc():
p.do('cuda:0', lambda: None)
assertentered.wait(5)
t=threading.Thread(target=lambda: p.shutdown(wait=True), daemon=True)
t.start(); t.join(0.5)
assertt.is_alive() # shutdown is blocked# The context exit notifies the condition; shutdown now finishes.t.join(5)
assertnott.is_alive()
The janitor must be notified when shutdown sets the stop event. This belongs with the shutdown lifecycle fix and merits a regression test that holds no_auto_gc() open while shutdown begins.
Activity
Qubitium commentedon Nov 14, 2026
Additional GIL=0 shutdown deadlock on
mainat221cd564(separate from the queued-future behavior above).shutdown(wait=True)sets_stop_eventand_gc_event, then joins the janitor before stopping workers. The janitor can instead be blocked in_auto_gc_disable_cv.wait()insideno_auto_gc(). Shutdown never notifies that condition, so its join waits until the context exits; if the context remains open, it can wait indefinitely.Reproduced on Python 3.14.10 with
PYTHON_GIL=0,sys._is_gil_enabled() == False, Torch 2.15 CUDA, one GPU:The janitor must be notified when shutdown sets the stop event. This belongs with the shutdown lifecycle fix and merits a regression test that holds
no_auto_gc()open while shutdown begins.fix(threadx): drain accepted work and reject submissions after shutdo…