Skip to content

Commit 82a7e04

Browse files
committed
fix: add freeze_support to handle multiprocessing in PyInstaller builds
Ensure that helper processes spawned by multiprocessing (e.g., for HuggingFace downloads) do not accidentally re-execute the main CLI logic when running the frozen binary.
1 parent d066f5a commit 82a7e04

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/open_codex/main.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,14 @@ def main():
8585
one_shot_mode(prompt)
8686

8787
if __name__ == "__main__":
88+
# We call multiprocessing.freeze_support() because we are using PyInstaller to build a frozen binary.
89+
# When Python spawns helper processes (e.g., for Hugging Face downloads or resource tracking),
90+
# it uses sys.executable to start the current executable with special multiprocessing arguments.
91+
# Without freeze_support(), the frozen app would accidentally rerun the main CLI logic
92+
# and crash (e.g., with argparse errors).
93+
# freeze_support() ensures the subprocess is handled correctly without restarting the full app.
94+
# This is required on macOS and Windows, where "spawn" is the default multiprocessing method.
95+
# See: https://pyinstaller.org/en/stable/common-issues-and-pitfalls.html#when-to-call-multiprocessing-freeze-support
96+
from multiprocessing import freeze_support
97+
freeze_support()
8898
main()

0 commit comments

Comments
 (0)