Răsfoiți Sursa

raise exception if on_startup() is called too late

Falko Schindler 2 ani în urmă
părinte
comite
1dbfd6ec56
1 a modificat fișierele cu 2 adăugiri și 0 ștergeri
  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)