Repository navigation
[3.12] gh-125451: Fix deadlock in ProcessPoolExecutor shutdown (GH-125492) - #125599
Merged
Merged
Conversation
…ythonGH-125492) There was a deadlock when `ProcessPoolExecutor` shuts down at the same time that a queueing thread handles an error processing a task. Don't use `_shutdown_lock` to protect the `_ThreadWakeup` pipes -- use an internal lock instead. This fixes the ordering deadlock where the `ExecutorManagerThread` holds the `_shutdown_lock` and joins the queueing thread, while the queueing thread is attempting to acquire the `_shutdown_lock` while closing the `_ThreadWakeup`. (cherry picked from commit 760872e) Co-authored-by: Sam Gross <colesbury@gmail.com>
This was referenced Oct 16, 2024
5 tasks done
5 tasks done
danielhanchen
added a commit
to unslothai/unsloth
that referenced
this pull request
Dec 2, 2026
…he re-fork hang (#20665) ## Summary Inductor shuts its async compile pool down after 60 s idle and forks a new one on the next compile. On CPython 3.10, 3.11, 3.12.0 to 3.12.7 and 3.13.0, a fork that overlaps the old pool's shutdown can inherit a held `_shutdown_lock`, and the compile never returns (pytorch/pytorch#200848; fixed in CPython 3.12.8 and 3.13.1 by python/cpython#125599). Most Studio installs are not affected: `install.sh` uses a uv-managed CPython 3.13 on Linux, the macOS 3.12 fallback uses only managed builds, and Windows never re-forks the pool. The Docker Studio images (`Dockerfile.studio`, `Dockerfile.studio-rocm`) install with `UNSLOTH_PYTHON=3.12` on Ubuntu 24.04, where uv picks the system Python 3.12.3, and any Ubuntu 24.04 user passing `--python 3.12` lands there too. `main.py` now sets `TORCHINDUCTOR_QUIESCE_ASYNC_COMPILE_POOL=0` before torch is imported (so spawned workers inherit it), only on affected POSIX interpreters and only when the variable is unset. Fixed interpreters keep the default, so idle compile workers are still reclaimed there. The probe cache key ignores the variable, so cached probe results stay valid. ## Evidence The stdlib repro from pytorch#200848, run in parallel: | CPython | Result | |---|---| | 3.12.3 (uv-managed and Ubuntu system) | job lost | | 3.13.0 | job lost | | 3.12.8 | ok | | 3.13.1 | ok | `uv venv --python ">=3.12,<3.13"` on Ubuntu 24.04 with no managed 3.12 picks `/usr/bin/python3.12` (3.12.3), and the new gate reports it as affected and sets the variable. ## Tests `studio/backend/tests/test_inductor_pool_env.py`: the version gate, an explicit user value winning, the call happening before any torch import, the probe cache key, Inductor reading the variable as False, and the stdlib repro losing the job exactly when the gate says the interpreter is affected. ## Not covered A torch-level hang under a long-lived Studio server was not reproduced (the race window is tens of milliseconds); the evidence is the stdlib repro and the torch source.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There was a deadlock when
ProcessPoolExecutorshuts down at the same time that a queueing thread handles an error processing a task.Don't use
_shutdown_lockto protect the_ThreadWakeuppipes -- use an internal lock instead. This fixes the ordering deadlock where theExecutorManagerThreadholds the_shutdown_lockand joins the queueing thread, while the queueing thread is attempting to acquire the_shutdown_lockwhile closing the_ThreadWakeup.(cherry picked from commit 760872e)