Skip to content

Conversation

@Ankitsinghsisodya
Copy link

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 FileNotFoundError for base_library.zip during shutdown. This happens because
ProcessPoolExecutor worker processes attempt to import modules after PyInstaller has
begun cleanup of the frozen environment.

The fix adds a check for sys.frozen in reformat_many() to limit workers to 1 in
frozen builds, which forces use of ThreadPoolExecutor instead of
ProcessPoolExecutor. This avoids the shutdown race condition while still allowing
Black 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 ...

  • Implement any code style changes under the --preview style, following the
    stability policy?
  • Add an entry in CHANGES.md if necessary?
  • Add / update tests if necessary?
  • Add new / update outdated documentation?

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_environment verifies the mono-process fallback logic
works correctly.

Ankitsinghsisodya and others added 2 commits December 30, 2025 08:04
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
@github-actions
Copy link

diff-shades reports zero changes comparing this PR (e12918b) to main (c3cc5a9).


What is this? | Workflow run | diff-shades documentation

@cobaltt7
Copy link
Collaborator

cobaltt7 commented Jan 1, 2026

Hey @FrankPortman, are you able to test this fix? I've built the mac binary already (build logs)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PyInstaller related issue when using the prebuilt Black binary on Mac OSX

2 participants