Skip to content

Closing the window does not shutdown the app after hot reloading #5845

@Mick235711

Description

@Mick235711

First Check

  • I added a very descriptive title here.
  • This is not a security issue (those should be reported via the security advisory instead).
  • This is not a Q&A. I am sure something is wrong with NiceGUI or its documentation.
  • I used the GitHub search to find a similar issue and came up empty.

Example Code

from nicegui import app, ui

def app_startup():
    print('app startup')

def app_shutdown():
    print('app shutdown')

app.on_startup(app_startup)
app.on_shutdown(app_shutdown)

@ui.page('/')
def index():
    ui.button('destroy window', on_click=lambda: app.native.main_window.destroy())
    ui.button('nicegui shutdown', on_click=lambda: app.shutdown())
    
ui.run(
    title="Some app",
    port=8502,
    native=True,
    reload=True,
    window_size=(1920, 1200),
    storage_secret='my secret'
)

Description

Very similar to #2107, but seems to be a different problem (or maybe the original fix is not enough), as the original problem is described to be windows only, but I'm on macOS now.

Specifically, the original issue itself is fixed: open the app, click either X or destroy window or nicegui shutdown, all three actions leads to a proper shutdown of the app even with reload=True. However, when you actually tries to use hot reload, the entire thing is again broken.

Full reproduction steps:

  1. Open the app
  2. Edit the file to add something irrelevant (like a comment), triggering an auto reload
  3. Press X or destroy window, the window closed but the app does not quit (the console is still in the app's process; in fact if you edit the file again the console will show a second hot reload message). Press nicegui shutdown still works properly.

Console output:

NiceGUI ready to go on http://127.0.0.1:8502
app startup
WARNING:  WatchFiles detected changes in 'test.py'. Reloading...
app shutdown
NiceGUI ready to go on http://127.0.0.1:8502
app startup
<Press Ctrl-C>app shutdown

NiceGUI Version

3.8.0

Python Version

3.14.3

Browser

Other

Operating System

macOS

Additional Context

macOS Tahoe 26.3 (arm64) on an M2 Pro MacBook Pro

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugType/scope: Incorrect behavior in existing functionalityin progressStatus: Someone is working on it

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions