Added try guard to sio.receive in writer

This commit is contained in:
Casey 2024-07-07 19:36:33 +03:00
parent 5df9dd4598
commit 4527954cad
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
1 changed files with 6 additions and 2 deletions

View File

@ -1,6 +1,7 @@
import asyncio import asyncio
from typing import Callable, NewType, Optional from typing import Callable, NewType, Optional
from socketio import AsyncClient, AsyncSimpleClient from socketio import AsyncClient, AsyncSimpleClient
import socketio
from aiohttp import ClientSession, ClientTimeout from aiohttp import ClientSession, ClientTimeout
from aiohttp_socks import ProxyConnector from aiohttp_socks import ProxyConnector
from PIL import Image, ImageFont, ImageDraw, ImageFilter, ImageSequence, ImageChops from PIL import Image, ImageFont, ImageDraw, ImageFilter, ImageSequence, ImageChops
@ -255,7 +256,10 @@ class AsyncBotManager:
await sio.emit("toggle_bit", {"index": index}) await sio.emit("toggle_bit", {"index": index})
await asyncio.sleep(delay) await asyncio.sleep(delay)
self._active.add(bot_index) self._active.add(bot_index)
try:
await sio.receive(0.1) await sio.receive(0.1)
except socketio.exceptions.TimeoutError:
print(f"read failed in {bot_index}")
async def __aenter__(self): async def __aenter__(self):
self._listener_task = asyncio.create_task(self.listener()) self._listener_task = asyncio.create_task(self.listener())
@ -412,7 +416,7 @@ async def amain() -> None:
) )
else: else:
res = await asyncio.gather( res = await asyncio.gather(
*[mgr.writer(i) for i in range(settings["n_bots"])], *[mgr.writer(i, None, settings["delay"]) for i in range(settings["n_bots"])],
return_exceptions=True, return_exceptions=True,
) )