Unable to start UI when invoked as a module #1993
Replies: 7 comments 3 replies
-
Hi @denravonska, thanks for reporting this issue! In the case Unfortunately, I don't know how to fix that. Does any else have an idea? |
Beta Was this translation helpful? Give feedback.
-
Thanks for looking into this. I figured it was something non-trivial related to outside circumstances. For now I'll run the code as an application instead of a module as a workaround. I'll yell if I happen to stumble upon a solution for this. |
Beta Was this translation helpful? Give feedback.
-
I converted this issue into a feature request because it's not really an issue with the existing feature set. But of course, it would be nice to add support for it in the future. If anyone has an idea how to achieve it, we're all ears. 😀 |
Beta Was this translation helpful? Give feedback.
-
@falkoschindler Is this still an issue? Perhaps this may help. I once had a problem with creating a listener process exactly once. Couldn't use Solution: environment variables. Set env variable when code first runs and creates listener. Spawned child processes inherit environment. Repeat loads of module in children check for env variable and know listener has already been created. This situation is a bit different. But the principle of using env vars to pass info to children could work. Perhaps ui.run can set an env var with name of module / function that invoked it? When If you need to save more state, perhaps you could use pickle and the fileystem? Save a file like Would that help? Without knowing the precise reload call sequence, perhaps I missed something. More detail on previous solution here: |
Beta Was this translation helpful? Give feedback.
-
As a workaround. |
Beta Was this translation helpful? Give feedback.
-
Running into this was kinda my first impression of using NiceGUI.
[project.scripts]
mypackage = "mypackage.__main__:main" which has I added a, [project.scripts]
mypackage-dev = "mypackage.app:run" but currently I'm quite clueless as to how package organization should go from the aspect of what should be reloaded. I imagine only reloading the ui logic is the way to go. But, that... will bring in weird constraints sooner or later. I would appreciate someone pointing to info exactly on this. |
Beta Was this translation helpful? Give feedback.
-
Simplest solution is to have a mainguard like so: from multiprocessing import current_process
if __name__ == "__main__" or current_process().name != "MainProcess":
... As |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
Branched off from #181
It seems that when invoking your code as a module (
python -m ...
) it triggers the same error as having the incorrect main guard, even when not using any guards.Small sample project setup at https://github.com/denravonska/nicegui-error-sample.
Beta Was this translation helpful? Give feedback.
All reactions