|
@@ -40,18 +40,17 @@ class Timer:
|
|
|
|
|
|
async def _run_once(self) -> None:
|
|
async def _run_once(self) -> None:
|
|
with self.slot:
|
|
with self.slot:
|
|
|
|
+ await self._handshake()
|
|
await asyncio.sleep(self.interval)
|
|
await asyncio.sleep(self.interval)
|
|
await self._invoke_callback()
|
|
await self._invoke_callback()
|
|
self.cleanup()
|
|
self.cleanup()
|
|
|
|
|
|
async def _run_in_loop(self) -> None:
|
|
async def _run_in_loop(self) -> None:
|
|
with self.slot:
|
|
with self.slot:
|
|
|
|
+ await self._handshake()
|
|
while True:
|
|
while True:
|
|
if self.slot.parent.client.id not in globals.clients:
|
|
if self.slot.parent.client.id not in globals.clients:
|
|
break
|
|
break
|
|
- if not self.slot.parent.client.shared:
|
|
|
|
- # NOTE: we need to wait for the client before state can be further manipulated (see https://github.com/zauberzeug/nicegui/issues/206)
|
|
|
|
- await self.slot.parent.client.handshake()
|
|
|
|
try:
|
|
try:
|
|
start = time.time()
|
|
start = time.time()
|
|
if self.active:
|
|
if self.active:
|
|
@@ -73,6 +72,14 @@ class Timer:
|
|
except Exception:
|
|
except Exception:
|
|
traceback.print_exc()
|
|
traceback.print_exc()
|
|
|
|
|
|
|
|
+ async def _handshake(self) -> None:
|
|
|
|
+ '''Wait for the client handshake before the timer callback can can be allowed to manipulate the state.
|
|
|
|
+ See https://github.com/zauberzeug/nicegui/issues/206 for details.
|
|
|
|
+ '''
|
|
|
|
+
|
|
|
|
+ if not self.slot.parent.client.shared:
|
|
|
|
+ await self.slot.parent.client.handshake()
|
|
|
|
+
|
|
def cleanup(self) -> None:
|
|
def cleanup(self) -> None:
|
|
self.slot = None
|
|
self.slot = None
|
|
self.callback = None
|
|
self.callback = None
|