Browse Source

stop timers when UI is stopping or stopped

Falko Schindler 2 years ago
parent
commit
4480383680
1 changed files with 4 additions and 1 deletions
  1. 4 1
      nicegui/functions/timer.py

+ 4 - 1
nicegui/functions/timer.py

@@ -40,7 +40,8 @@ class Timer:
         with self.slot:
             await self._connected()
             await asyncio.sleep(self.interval)
-            await self._invoke_callback()
+            if globals.state not in [globals.State.STOPPING, globals.State.STOPPED]:
+                await self._invoke_callback()
         self.cleanup()
 
     async def _run_in_loop(self) -> None:
@@ -49,6 +50,8 @@ class Timer:
             while True:
                 if self.slot.parent.client.id not in globals.clients:
                     break
+                if globals.state in [globals.State.STOPPING, globals.State.STOPPED]:
+                    break
                 try:
                     start = time.time()
                     if self.active: