ClimenteA / flaskwebgui

Create desktop applications with Flask/Django/FastAPI!
MIT License
704 stars 71 forks source link

Closing application does not work in Mac #156

Open malkarouri opened 3 weeks ago

malkarouri commented 3 weeks ago

I am using Python 3.12 on MacOS 14.6, using FastAPI. I am using the exact code to close application as shown in the application. The browser is not closed on pressing the Close button. The server shuts down, but Chrome stays open with a clear page (or whatever the Close function returns after calling close_application.

I can trace the issue to the way the run function works in FlaskUI for MacOS (Darwin). It seems that the run functions starts a new process. The value of the global variable FLASKWEBGUI_BROWSER_PROCESS is not shared between the old and new process, causing the call to close_application to find the process value as None and not terminate it.

ClimenteA commented 2 weeks ago

Hi,

Thank you for opening this issue. I don't have a Mac to test this, but try this: in the flaskwebgui.py source file on line 256 add the following:

if OPERATING_SYSTEM == "darwin":
    multiprocessing.set_start_method("fork")

before FLASKWEBGUI_BROWSER_PROCESS = subprocess.Popen(self.browser_command).

Please tell me if that fixes the issue or not.