GitHub Repo
PyTorch Community Reports Windows LibTorch Process Hang That Can Be Triggered by Setting Thread Count Alone
A report filed November 14 says a Windows LibTorch CPU program may fail to exit after setting two threads, even without loading a model. The report points to thread-pool cleanup as a possible cause; maintainers have not yet confirmed the issue or provided a fix.

On November 14, the PyTorch community received a report of an issue with Windows LibTorch: a minimal C++ program that only calls at::set_num_threads(2) may hang after main finishes, without tensor operations, a model, or CUDA. This puts the issue squarely in the lifecycle management of applications embedding LibTorch. Report and reproduction
According to the submitter’s tests, the official CPU packages 2.14.1 and 2.15.0 each failed to exit within ten seconds in 13 of 30 independent process launches. The November 13 nightly build did so in 19 of 30 launches. All timed-out cases had already printed the main program’s completion message, so checking only for a “work completed” log could miss a failure during shutdown. These figures come from a single Windows 11 machine and should not be treated as rates across environments. Test results
The report narrows the suspected cause to the pthreadpool cleanup path: during DLL unloading, a static thread pool is destroyed and waits indefinitely while trying to acquire a mutex. Microsoft’s documentation explains that ExitProcess terminates other threads before sending DLL unload notifications; if a terminated thread holds a lock needed by the DLL-unload code, a deadlock can occur. This supports the mechanism proposed in the report, but does not independently establish LibTorch’s full root cause. Windows process termination sequence
The submitter also found that initializing with one thread before setting the count to two allowed all 30 test runs to exit normally. However, the helper thread pool is created only once, so this workaround may leave it operating with one thread; the original performance should not be assumed. Engineering teams can include “the process exits successfully” in deployment checks and track whether maintainers can reproduce the issue, whether a fix covers the upstream dependency, and which release includes it. The issue remains open, with no linked fix PR. The investigation text also states that it was generated by Codex, so the tests and root-cause assessment still need independent review. Limitations and current status