-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Fix PyInstaller shutdown errors on macOS #4930
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix PyInstaller shutdown errors on macOS #4930
Conversation
In frozen (PyInstaller) builds, disable multiprocessing by limiting workers to 1. This prevents shutdown errors caused by worker processes attempting to import modules after PyInstaller cleanup begins. Fixes psf#4823
for more information, see https://pre-commit.ci
|
Hey @FrankPortman, are you able to test this fix? I've built the mac binary already (build logs) (25.12.0 binary for comparison) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Fixes a shutdown-time import race in PyInstaller-frozen Black binaries (notably on macOS) by preventing ProcessPoolExecutor usage in frozen environments.
Changes:
- In
reformat_many(), detect frozen builds viasys.frozenand forceworkers = 1to avoid multiprocessing workers. - Add a packaging changelog entry describing the PyInstaller shutdown fix.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/black/concurrency.py |
Forces single-worker execution in frozen builds to avoid ProcessPoolExecutor shutdown/import issues. |
CHANGES.md |
Documents the PyInstaller/frozen-build shutdown fix under Packaging. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
This reverts commit c676452.
|
Fuzz error is unrelated to this PR |
In frozen (PyInstaller) builds, disable multiprocessing by limiting workers to 1. This
prevents shutdown errors caused by worker processes attempting to import modules after
PyInstaller cleanup begins.
Fixes #4823
Description
When using the prebuilt Black binary on macOS (built with PyInstaller), users encounter
a
FileNotFoundErrorforbase_library.zipduring shutdown. This happens becauseProcessPoolExecutorworker processes attempt to import modules after PyInstaller hasbegun cleanup of the frozen environment.
The fix adds a check for
sys.frozeninreformat_many()to limit workers to 1 infrozen builds, which forces use of
ThreadPoolExecutorinstead ofProcessPoolExecutor. This avoids the shutdown race condition while still allowingBlack to function correctly.
This approach mirrors the existing fallback behavior for environments that don't support
multiprocessing (like AWS Lambda or Termux).
Checklist - did you ...
--previewstyle, following thestability policy?
CHANGES.mdif necessary?Note on tests: No automated tests can be added for this fix because the issue only
manifests in PyInstaller-frozen builds. The existing test
test_works_in_mono_process_only_environmentverifies the mono-process fallback logicworks correctly.