@@ -27,6 +27,7 @@ server: Server
loop: Optional[asyncio.AbstractEventLoop] = None
log: logging.Logger = logging.getLogger('nicegui')
state: State = State.STOPPED
+ui_run_has_been_called: bool = False
host: str
port: int
@@ -47,6 +47,14 @@ def get_components(name: str):
@app.on_event('startup')
def handle_startup(with_welcome_message: bool = True) -> None:
+ if not globals.ui_run_has_been_called:
+ raise RuntimeError('\n\n'
+ 'You must call ui.run() to start the server.\n'
+ 'If ui.run() is behind a main guard\n'
+ ' if __name__ == "__main__":\n'
+ 'remove the guard or replace it with\n'
+ ' if __name__ in {"__main__", "__mp_main__"}:\n'
+ 'to allow for multiprocessing.')
globals.state = globals.State.STARTING
globals.loop = asyncio.get_running_loop()
for t in globals.startup_handlers:
@@ -48,6 +48,7 @@ def run(*,
(possible entries: audio, chart, colors, interactive_image, joystick, keyboard, log, scene, table, video)
:param tailwind: whether to use Tailwind (experimental, default: `True`)
'''
+ globals.ui_run_has_been_called = True
globals.host = host
globals.port = port
globals.reload = reload