Skip to content
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

Hangs forever if launched using typer #3943

Open
traverseda opened this issue Nov 3, 2024 · 1 comment
Open

Hangs forever if launched using typer #3943

traverseda opened this issue Nov 3, 2024 · 1 comment

Comments

@traverseda
Copy link

traverseda commented Nov 3, 2024

import typer
from nicegui import ui

def main(
        port: int = 5123,
    ):

    @ui.page('/')
    def main_page():
        ui.label('Hello NiceGUI!')
        ui.icon('thumb_up')
        ui.markdown('This is **Markdown**.')
        ui.html('This is <strong>HTML</strong>.')
        with ui.row():
            ui.label('CSS').style('color: #888; font-weight: bold')
            ui.label('Tailwind').classes('font-serif')
            ui.label('Quasar').classes('q-ml-xl')
        ui.link('NiceGUI on GitHub', 'https://github.com/zauberzeug/nicegui')

    ui.run(port=5123, dark=None)


if __name__ in {"__main__", "__mp_main__"}:
    #main() #Works
    typer.run(main) #Does not work

No debug output, it just doesn't run.

@rodja
Copy link
Member

rodja commented Nov 4, 2024

You need to set reload=False:

import typer
from nicegui import ui

def main(port: int = 5123):
    @ui.page('/')
    def main_page():
        ui.label('Hello NiceGUI!')

    ui.run(port=port, reload=False)

if __name__ in {"__main__", "__mp_main__"}:
    typer.run(main)

This seems to be caused by the fact that the reloader (watchdog package) runs the file twice: https://github.com/zauberzeug/nicegui/wiki/FAQs#why-is-my-code-executed-twice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants