-
-
Notifications
You must be signed in to change notification settings - Fork 629
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
ui.run(native=True) does not exit python execution when exiting native app. #3931
Comments
I am also not wanting to ctrl + c in the terminal. I want to be able to run this and not have manual interference to stop python. Also, why does "Done!" get printed twice? |
I see that now, but my main question still stands. Do I have to shutdown the server manually? |
I agree. The program should exit automatically if you close the main window. And, at least on OS X, it does exactly that. And with the following modifications you'll only see a single "Done" printed after the window is closed: from nicegui import ui
ui.label('page with custom title')
if __name__ == '__main__':
ui.run(reload=False, native=True)
print("Done!") |
You can shutdown the server with a button, if that helps ? Or just call it as a function when you decide that the program is finished. from nicegui import ui, app
from datetime import datetime
ui.button('shutdown', on_click=app.shutdown)
app.on_shutdown(lambda: print(f'shutdown: {datetime.now()}'))
ui.run(native=True) |
when we close the app it's running in the background in the task manager. Can I use it for this purpose. |
Yes, it should. You should just try it ! |
Okay, but will trigger this app.shutdown event, in your case it's button in the UI but i want it to trigger when window close X button clicked: |
Description
When running, I get this output while the native app is open (not on a browser):
Then, after pressing the close button on the app, the console still looks the same as above, and python is still running.
I expect the print("Done!") to not execute until after the app is closed, and then I expect python to halt execution, but it doesn't. Can someone please point me to how python ends on exit of native app? Thanks in advance.
I am running python 3.11.6 and nicegui 2.5.0.
The text was updated successfully, but these errors were encountered: