marcelotduarte / cx_Freeze

cx_Freeze creates standalone executables from Python scripts, with the same performance, is cross-platform and should work on any platform that Python itself works on.
https://marcelotduarte.github.io/cx_Freeze/
Other
1.28k stars 210 forks source link

Version 7.1.0 (and 7.1.0.post0) break FastAPI/hypercorn #2433

Closed Daniel-I-Am closed 2 weeks ago

Daniel-I-Am commented 3 weeks ago

Describe the bug When running a program built with cx_freeze starting version 7.1.0, it adds additional arguments, which hypercorn does not accept. These arguments seem to be related to multiprocessing integration.

This causes programs built with 7.1.0 or up, to no longer be functional.

A temporary workaround is to downgrade back to 7.0.0.

To Reproduce All that is required is to run a hypercorn/FastAPI server (or it seems anything that uses multiprocessing) built with cx_Freeze on version 7.0.0 or 7.1.0.post0 (and also 7.1.0 was affected).

I added a full example to a reproduction repository: https://github.com/Daniel-I-Am/cx_freeze-fastapi-repro

Expected behavior I would expect programs that can be built with 7.0.0 to also be able to be built with 7.1.0.

Desktop (please complete the following information):

ntindle commented 3 weeks ago
from multiprocessing import Process, freeze_support

def f():
    print("Hello from cx_Freeze")

if __name__ == "__main__":
    freeze_support()
    Process(target=f).start()

Potentially related broken case on macos without fastapi

marcelotduarte commented 3 weeks ago

@Daniel-I-Am I confirm the bug. I'll work on it. @ntindle Can you check if #2435 is more related to your use case?

ntindle commented 3 weeks ago

I think you're right that the issue you linked is more related

marcelotduarte commented 2 weeks ago

@Daniel-I-Am I improved the hook for multiprocessing. You can test the patch in the latest development build: pip install --force --no-cache --pre --extra-index-url https://marcelotduarte.github.io/packages/ cx_Freeze The provisional documentation: https://cx-freeze--2443.org.readthedocs.build/en/2443/faq.html#multiprocessing-support The must create a hypercorn.py script with the additional freeze_support:

from hypercorn.__main__ import main
from multiprocessing import freeze_support

if __name__ == "__main__":
    freeze_support()
    sys.exit(main())
Daniel-I-Am commented 2 weeks ago

I installed the development build and it looks like the problem is fixed now. I see the warning about requiring multiprocessing.freeze_support() to be called, but the application starts fine (as I'm running it in a linux environment).

I will have to check how to insert that call when using the Hypercorn package binary. But it seems Hypercorn is starting fine now. Thanks for the quick fix!

marcelotduarte commented 1 week ago

I see the warning about requiring multiprocessing.freeze_support() to be called, but the application starts fine (as I'm running it in a linux environment).

Added a way to hide the message, check the provisional documentation: https://cx-freeze--2443.org.readthedocs.build/en/2443/faq.html#multiprocessing-support

marcelotduarte commented 1 week ago

Release 7.1.1 is out! Documentation