瀏覽代碼

raise exception if on_startup() is called too late

Falko Schindler 2 年之前
父節點
當前提交
1dbfd6ec56
共有 1 個文件被更改,包括 2 次插入0 次删除
  1. 2 0
      nicegui/lifecycle.py

+ 2 - 0
nicegui/lifecycle.py

@@ -14,6 +14,8 @@ def on_disconnect(self, handler: Union[Callable, Awaitable]):
 
 
 def on_startup(self, handler: Union[Callable, Awaitable]):
+    if globals.state == globals.State.STARTED:
+        raise RuntimeError('Unable to register another startup handler. NiceGUI has already been started.')
     globals.startup_handlers.append(handler)