-
-
Notifications
You must be signed in to change notification settings - Fork 533
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
CLI pattern if __name__ == "__main__": main()
does not work with misleading message
#181
Comments
if __name__ == "__main__": main()
does not workif __name__ == "__main__": main()
does not work with misleading message
When Uvicorn is reloading the app (which happens for the first time right after starting the script), it re-evaluates main.py while searching for the nicegui:app object. In contrast to the original process, this "reloader" process has Technically I don't see an easy solution for supporting the default main guard If you want to avoid the code in from nicegui import ui
@ui.page('/')
def main_page():
ui.label('Hello NiceGUI!')
ui.button('BUTTON', on_click=lambda: ui.notify('button was pressed'))
ui.run(port=8082) Personally I'm not sure if you really need a main guard. Ideally your main script is short and concise, so that it does not need to be imported from anywhere. |
I want my main script to serve as a CLI primarily and be able to spin up a web gui as an option. |
I'll close this issue, since I don't see how we can avoid the conflict with the main guard. Using NiceGUI as a secondary mode in an otherwise headless CLI application in combination with |
Is this supposed to work when you invoke your code as a module? I get the exact same error message when using a from nicegui import ui
ui.run()
|
Hi @denravonska! |
@falkoschindler Done, #1111 :) |
related to #143
One of the patterns for running CLI programs is:
This does not work with
reload=True
, because the reloadable__name__
is__mp_main__
instead.So I made it work using second entry:
Any idea what causes this and/or whether it can be fixed in
nicegui
itself?The text was updated successfully, but these errors were encountered: