-
-
Notifications
You must be signed in to change notification settings - Fork 605
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
NiceGUI runs python code twice #794
Comments
Thanks for bringing this up, @JS-Aibel! This is known behavior. When running with
Note that the script is evaluated twice only when starting it. The auto-reload on code change will re-evaluate only once. To avoid the re-evaluation, you have several options:
|
We solved this by creating an empty UI if reload is enabled and if it is the process that will just start the script again RELOAD = True
def main():
# If reload is enabled, then it has to run the main program as a subprocess (https://github.com/zauberzeug/nicegui/issues/794)
# => it runs the file again as a subprocess causing everything to be executed twice
# => This reload runner doesn't need to run the actual code
if RELOAD and __name__ == '__main__':
ui.run(host='127.0.0.1', port=8080, reload=RELOAD)
return
print("Building UI")
ui.label('Test')
ui.run(host='127.0.0.1', port=8080, reload=RELOAD)
if __name__ in ['__main__', '__mp_main__']:
main() |
Description
When running the code below the python code get executed twice.
When running scripts that takes a while, it is bad for performance that it has to run twice.
Output from terminal:
The text was updated successfully, but these errors were encountered: