async def broadcast_until_stopped(self, generate_message: callable(None), stop_signal: trio.Event, update_interval=0.25): print("movement starting") while not stop_signal.is_set(): msg = await generate_message() await self.broadcast(msg) await trio.sleep(update_interval) print("movement stopped")
async def monitor(self, check_rate, max_time, stop_signal: trio.Event): self._mon_stop = stop_signal while not stop_signal.is_set(): if self.resources_available(): async with self.resource_lock: if self.resources_available(): res = await self.recv_chan.receive() last_used = time.time() - res.last_use print(f"{res.name}:mon: res last used {last_used}") if last_used > max_time: print(f"closing res {res.name}") self.current_resources -= 1 await res.aclose() else: await self.send_chan.send(res) else: print("no resources") await trio.sleep(check_rate) self._mon_stop = None print("closing monitor...")
async def _heartbeat_task(self, kill_switch:trio.Event): while not kill_switch.is_set(): await trio.sleep(1)