Skip to content
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

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

Closed
Daniel-I-Am opened this issue Jun 3, 2024 · 7 comments · Fixed by #2443
Closed

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

Daniel-I-Am opened this issue Jun 3, 2024 · 7 comments · Fixed by #2443

Comments

@Daniel-I-Am
Copy link

Daniel-I-Am commented Jun 3, 2024

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):

  • Platform information: Docker python:3.12-alpine on linux
  • OS architecture: amd64
  • cx_Freeze version: 7.1.0.post0
  • Python version: 3.12
@ntindle
Copy link
Contributor

ntindle commented Jun 3, 2024

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
Copy link
Owner

marcelotduarte commented Jun 4, 2024

@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
Copy link
Contributor

ntindle commented Jun 4, 2024

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

@marcelotduarte
Copy link
Owner

marcelotduarte commented Jun 7, 2024

@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
Copy link
Author

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
Copy link
Owner

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
Copy link
Owner

Release 7.1.1 is out!
Documentation

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 a pull request may close this issue.

3 participants