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
Manager not properly shut down in concurrency module - violates multiprocessing best practices #4950
In src/black/concurrency.py, schedule_formatting() creates a multiprocessing.Manager() when write_back is DIFF or COLOR_DIFF, but the Manager is never explicitly shut down. code location:
Since Manager starts a separate server process, not calling shutdown() (or using a context manager) can lead to resource leaks when Black is used as a library or repeatedly in a long-running process. This is mostly hidden in CLI usage because the process exits immediately.
It would be safer to explicitly shut down the Manager or manage it via a context manager to match Python’s multiprocessing best practices.
@cobaltt7 Thanks! I’ve opened a PR that addresses this by explicitly shutting down
the multiprocessing.Manager() in schedule_formatting() for DIFF or
COLOR_DIFF modes.
The PR also adds a deterministic unit test to ensure the Manager is always
shut down, including on exceptions or cancellation.
Activity
cobaltt7 commentedon Jan 10, 2026
PRs welcome!
nileshsingal commentedon Jan 10, 2026
@cobaltt7 Thanks! I’ve opened a PR that addresses this by explicitly shutting down
the multiprocessing.Manager() in schedule_formatting() for DIFF or
COLOR_DIFF modes.
The PR also adds a deterministic unit test to ensure the Manager is always
shut down, including on exceptions or cancellation.
Looking forward to your review.