Parcourir la source

raise exception if on_startup() is called too late

Falko Schindler il y a 2 ans
Parent
commit
1dbfd6ec56
1 fichiers modifiés avec 2 ajouts et 0 suppressions
  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)