From 8828fa13fc706586e38be586011a5cd869d1a775 Mon Sep 17 00:00:00 2001 From: Guillermo Rodriguez Date: Fri, 7 Feb 2025 23:17:33 -0300 Subject: [PATCH] Add table_index system in poller in order for daemon to be aware of stale data --- skynet/dgpu/daemon.py | 7 +++++++ skynet/dgpu/network.py | 3 +++ 2 files changed, 10 insertions(+) diff --git a/skynet/dgpu/daemon.py b/skynet/dgpu/daemon.py index fabe5a9..2fc2159 100755 --- a/skynet/dgpu/daemon.py +++ b/skynet/dgpu/daemon.py @@ -183,9 +183,16 @@ async def maybe_serve_one( async def dgpu_serve_forever(config: Config, conn: NetConnector): await maybe_update_tui_balance(conn) + last_poll_idx = -1 try: while True: await conn.wait_data_update() + if conn.poll_index == last_poll_idx: + await trio.sleep(config.poll_time) + continue + + last_poll_idx = conn.poll_index + queue = conn._tables['queue'] random.shuffle(queue) diff --git a/skynet/dgpu/network.py b/skynet/dgpu/network.py index a54c032..e6585d1 100755 --- a/skynet/dgpu/network.py +++ b/skynet/dgpu/network.py @@ -67,6 +67,8 @@ class NetConnector: self.ipfs_client = AsyncIPFSHTTP(config.ipfs_url) + # poll_index is used to detect stale data + self.poll_index = 0 self._tables = { 'queue': [], 'requests': {}, @@ -180,6 +182,7 @@ class NetConnector: self._data_event.set() await trio.sleep(max(poll_time - elapsed, 0.1)) self._data_event = trio.Event() + self.poll_index += 1 async def should_cancel_work(self, request_id: int) -> bool: logging.info('should cancel work?')