Skip to content
Discussion options

You must be logged in to vote

With the ui.run parameters uvicorn_reload_dirs, uvicorn_reload_includes, and uvicorn_reload_excludes you should be able to limit NiceGUI's file watcher so that a second watcher does not interfere:

import watchfiles
from nicegui import app, events, ui

async def watch_my_file():
    async for change in watchfiles.awatch('my_file.txt'):
        print(change, flush=True)
        ui.notify('File changed!')

ui.timer(0, watch_my_file, once=True)

ui.run(uvicorn_reload_excludes='my_file.txt')

The ui.timer is a little trick to run the async watch_my_file() in a UI context so that ui.notify knows the corresponding client.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@smojef
Comment options

@smojef
Comment options

@falkoschindler
Comment options

Answer selected by smojef
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants