zauberzeug / nicegui

Create web-based user interfaces with Python. The nice way.
https://nicegui.io
MIT License
10.01k stars 594 forks source link

Changing NiceGUI port while running the web server breaks the old port page #3655

Open irinelul opened 2 months ago

irinelul commented 2 months ago

Description

While trying out the different content on the niceGUI page, I noticed that the pages broke down, not being able to further modify the content from them. I can't run it on 8080 so I ran it on another port.

from nicegui import ui

with ui.card():
    ui.label('Card content')
    ui.button('Add label', on_click=lambda: ui.label('Click!'))
    ui.timer(1.0, lambda: ui.label('Tick!'), once=True)

ui.run(port=8000)

I used this template.

  1. Create a main.py file with the code above.
  2. Modify the port from 8000 to 1234 and the content to make it distinguishable
  3. The file watcher will find the difference and try to refresh the page
  4. ! Here it will say that it's still listening to the old port!
  5. At this point:
  6. The localhost:8000 is now still available with the old content
  7. The localhost:1234 does not exist
  8. Exit the NiceGUI script with CTRL C
  9. localhost:8000 still persists
  10. localhost:1234 is now available with the changes made.

WindowsTerminal_WJ34n9NNh2

For some reason, the process is alive in chrome and listens to both ports.
OS: W11 Python 3.12 Browser chrome

chrome_yfHC07MnF5

falkoschindler commented 2 months ago

Hi @irinelul,

As mentioned in the documentation, most ui.run parameters, like port, need to full restart to become effective.

Nevertheless, the leftover processes are unexpected. Is this also the case without changing the port? Can anyone reproduce this problem?

adarshpunj commented 1 month ago

Can confirm there are no leftover processes after Ctrl+C.

As @falkoschindler mentioned file watcher doesn't register changes in ui.run parameters. However, after restarting, it's running on 1234, and 8000 no longer exists.

Is it more of a OS issue?

OS NiceGUI Python
macOS 13.2 1.4.30 3.10
rodja commented 1 month ago

Can this be reproduced with a FastPAI / uvicorn scenario?