nicegui: Reload slow, no response to ctrl-C on Windows

Description

A simple application starts up in a second or two, but on making a change, reloading may take 10 seconds or more and may hang. Additionally, when hung, the terminal (both PowerShell and CMD) has no response to ctrl-c or clicking the close button. It’s been about a year since I’ve used NiceGUI on Windows (I mostly use Linux) and I don’t remember this behavior before.

It sounds a bit like https://github.com/zauberzeug/nicegui/issues/3344, but this isn’t in PyCharm. There are also some issues in uvicorn like https://github.com/encode/uvicorn/issues/1972 that sound related, but I know enough about the NiceGUI stack to know if that could be the root cause.

My test script is:

from nicegui import ui

ui.button("Button 1")
ui.button("Button 2")
ui.button("Button 3")

ui.run()

Steps to recreate:

  1. Make a simple NiceGUI script like the above named simple.py.
  2. Run python simple.py in a Windows terminal.
  3. Comment out one of the ui.button(...) calls and save the file.
  4. Wait for “… Reloading…” to complete and show “NiceGUI ready to go…”

Environment:

  • Windows 11 (also Windows 10, but mostly testing on Windows 11)
  • Python 3.12.4 (x64)
  • nicegui 1.4.37
  • uvicorn 0.30.6
  • fastapi 0.109.2

Edit: I tried the same test in WSL2 on the same computer and reloads are very fast, under a second.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 24 (10 by maintainers)

Most upvoted comments

@superlou To remove NiceGUI from the equation, I like to use the following minimal FastAPI/Uvicorn example: … You can store this as main.py and run via python3 main.py.

That code has largely the same behavior, though for whatever reason, both nicegui and that fastapi snippet don’t hang as badly as they seemed to when I first opened this issue. That said, the vanilla fastapi snippet still doesn’t automatically refresh and appears frozen until I right-click on the terminal. That seems to confirm @sht2017 thought that this isn’t a nicegui root cause.

The problem still generally persists with version 2.11, though with the very simple test example I’ve been doing, I just noticed that if I wait for the browser to autorefresh, it may take 5 to 30 seconds. If I right-click on the Windows Terminal with Powershell that I used to start the nicegui script, it updates a second or so after right-clicking. I’m not sure what that means, but it seems interesting.

Thanks everyone for the investigation! Indeed it looks like a uvicorn issue which we can’t do much about. It needs to be fixed upstream. Let’s close this issue.

I’m also using Windows 11, Python 3.12.2, and NiceGUI 2.9.0. On Windows, I have a project that even fails to use auto-reloading. When using the default log level of NiceGUI, it stops at the “WARNING: WatchFiles detected changes in ‘main.py’. Reloading…” of WatchFile; when switching the log level to Debug, it stops at the “INFO: Finished server process [26852]” of Uvicorn. I encountered this issue when using NiceGUI 2.5.0 on Windows and it still wasn’t resolved in NiceGUI 2.11. Additionally, I have encountered other problems in the new versions of NiceGUI, and I will open a new issue to explain them.

same issue here Windows 11 24h2 using default terminal (conhost) with powershell Python 3.11 Ctrl F5 doesn’t seem to help, only kill then restart in Task manager work

Same issue for me W11 Vscode Latest nicegui version Python 3.11 3.12 and 3.13

Works only if i CTRL F5 the browser or if I kill and restart it

@frankhuurman, I don’t think it’s filewatcher, only because when I save, it immediately pops up with the notification that a file changed. The issues happen in the delay after.

Does nicegui use uvicorn logging? This comment describes my ctrl-c behavior.