Added a bit of sleeping every 100 attempts

This commit is contained in:
Casey 2024-07-04 17:42:47 +03:00
parent b61dc0efa8
commit 897fbea54b
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
1 changed files with 11 additions and 7 deletions

View File

@ -108,13 +108,17 @@ class AsyncBotManager:
async with AsyncSimpleClient(http_session=http) as sio: async with AsyncSimpleClient(http_session=http) as sio:
await sio.connect(f"{self.base}/socket.io") await sio.connect(f"{self.base}/socket.io")
while not self._shutdown: while not self._shutdown:
index, expected = choice(list(self.difference.items())) diff = list(self.difference.items())
y, x = divmod(index, 1000) for _ in range(100):
current = self.canvas.getpixel((x, y)) > 0 # type: ignore index, expected = choice(diff)
if current != expected: y, x = divmod(index, 1000)
print(bot_index, "swap", x, y) current = self.canvas.getpixel((x, y)) > 0 # type: ignore
await sio.emit("toggle_bit", {"index": index}) if current != expected:
await asyncio.sleep(0.25) print(f"[{bot_index:2d}] swap {x:3d} {y:3d}")
await sio.emit("toggle_bit", {"index": index})
await asyncio.sleep(0.25)
break
await asyncio.sleep(0.1)
async def __aenter__(self): async def __aenter__(self):
self._listener_task = asyncio.create_task(self.listener()) self._listener_task = asyncio.create_task(self.listener())