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?')