flaskwebgui icon indicating copy to clipboard operation
flaskwebgui copied to clipboard

Closing application does not work in Mac

Open malkarouri opened this issue 1 year ago • 4 comments

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.

malkarouri avatar Aug 30 '24 12:08 malkarouri

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.

ClimenteA avatar Sep 03 '24 05:09 ClimenteA

I added this change on the new version, not tested (I don't own a mac). But, please reopen this issue if it's not solved.

ClimenteA avatar Sep 25 '24 08:09 ClimenteA

I added this change on the new version, not tested (I don't own a mac). But, please reopen this issue if it's not solved.我在新版本上添加了此更改,未经测试(我没有 mac)。但是,如果此问题未解决,请重新打开。

I believe this issue still remains unresolved as it hasn't fully addressed my problem. I suggest reopening this issue for further discussion and potential fixes.

i test result: python 3.10.3 sys:macos 10.15.7 code error: File "/.pyenv/versions/3.10.3/lib/python3.10/threading.py", line 946, in run self._target(*self._args, **self._kwargs) File "/venv/lib/python3.10/site-packages/flaskwebgui.py", line 265, in start_browser multiprocessing.set_start_method("fork") File "/.pyenv/versions/3.10.3/lib/python3.10/multiprocessing/context.py", line 243, in set_start_method raise RuntimeError('context has already been set')

haishiniu avatar Nov 05 '24 08:11 haishiniu

i think it could help you mammhoud/gui-web it was a same repo, enhanced and re structured to be more scalable it worked with auto close and with callbacks but be sure to close the page from Dock to fully close the WebDriver

mammhoud avatar Jun 10 '25 03:06 mammhoud

For mac this was set twice: multiprocessing.set_start_method("fork") that's probably why raise RuntimeError('context has already been set') happen.

I've updated it to be set only once on module initialization.

ClimenteA avatar Oct 04 '25 18:10 ClimenteA