How to shutdown the web app gracefully? #1370
Unanswered
ErikKalkoken
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Question
I am running a flet app in the browser.
When the user wants to exit the app he needs to manually close the browser tab AND exit the running Python script by pressing CTRL-C. In contrast with the desktop version the app just closes normally once the user clicks on the exit button (e.g. "x").
If he just closes the Python script, the browser app will keep running and conflict if the user tries to start the app again. If he just closes the windows tab, the Python script / fletd server keeps running and also conflicts when the user tries to start the app again.
For instance, if you just stop the Python script, the browser windows is currently trying to re-connect to the app, which looks like this:
The best approach I could find so far is adding an exit button and then killing the Python process. Then the user "just" needs to close the browser tab manually.
However a normal
exit()
or sys.exit() does not work, I need to kill the process viaos.kill(os.getppid(), 9)
, which is not a graceful shutdown of the server.Is there maybe a nicer way to do this? Ideally I would like to shutdown the Python process gracefully and close the browser tab after the user pressed a button. Or if that is not feasible due to permissions at least show a message on the browser tab like "The app is shutdown. You can close this tab now."
Code sample
No response
Error message
No response
------------------------------------------------------
Beta Was this translation helpful? Give feedback.
All reactions