From 5a067d60e7da20315cf50c72a8796213898aef0c Mon Sep 17 00:00:00 2001 From: Upstream Data Date: Fri, 26 Apr 2024 13:00:16 -0600 Subject: [PATCH] bug: remove some excepts that were catching propagated cancellations. --- pyasic/miners/factory.py | 75 ++++++++++++---------------------------- 1 file changed, 22 insertions(+), 53 deletions(-) diff --git a/pyasic/miners/factory.py b/pyasic/miners/factory.py index 31a9bb6b..bf9ff5e1 100644 --- a/pyasic/miners/factory.py +++ b/pyasic/miners/factory.py @@ -535,45 +535,25 @@ class MinerFactory: async def _get_miner_type(self, ip: str) -> MinerTypes | None: tasks = [ asyncio.create_task(self._get_miner_web(ip)), - # asyncio.create_task(self._get_miner_socket(ip)), + asyncio.create_task(self._get_miner_socket(ip)), ] return await concurrent_get_first_result(tasks, lambda x: x is not None) async def _get_miner_web(self, ip: str) -> MinerTypes | None: - tasks = [] - try: - urls = [f"http://{ip}/", f"https://{ip}/"] - async with httpx.AsyncClient( - transport=settings.transport(verify=False) - ) as session: - tasks = [ - asyncio.create_task(self._web_ping(session, url)) for url in urls - ] + urls = [f"http://{ip}/", f"https://{ip}/"] + async with httpx.AsyncClient( + transport=settings.transport(verify=False) + ) as session: + tasks = [asyncio.create_task(self._web_ping(session, url)) for url in urls] - text, resp = await concurrent_get_first_result( - tasks, - lambda x: x[0] is not None - and self._parse_web_type(x[0], x[1]) is not None, - ) - if text is not None: - mtype = self._parse_web_type(text, resp) - if mtype == MinerTypes.ANTMINER: - # could still be mara - auth = httpx.DigestAuth("root", "root") - res = await self.send_web_command( - ip, "/kaonsu/v1/brief", auth=auth - ) - if res is not None: - mtype = MinerTypes.MARATHON - return mtype - except asyncio.CancelledError: - for t in tasks: - t.cancel() - try: - await t - except asyncio.CancelledError: - pass + text, resp = await concurrent_get_first_result( + tasks, + lambda x: x[0] is not None + and self._parse_web_type(x[0], x[1]) is not None, + ) + if text is not None: + return self._parse_web_type(text, resp) @staticmethod async def _web_ping( @@ -621,27 +601,16 @@ class MinerFactory: return MinerTypes.AURADINE async def _get_miner_socket(self, ip: str) -> MinerTypes | None: - tasks = [] - try: - commands = ["version", "devdetails"] - tasks = [ - asyncio.create_task(self._socket_ping(ip, cmd)) for cmd in commands - ] + commands = ["version", "devdetails"] + tasks = [asyncio.create_task(self._socket_ping(ip, cmd)) for cmd in commands] - data = await concurrent_get_first_result( - tasks, - lambda x: x is not None and self._parse_socket_type(x) is not None, - ) - if data is not None: - d = self._parse_socket_type(data) - return d - except asyncio.CancelledError: - for t in tasks: - t.cancel() - try: - await t - except asyncio.CancelledError: - pass + data = await concurrent_get_first_result( + tasks, + lambda x: x is not None and self._parse_socket_type(x) is not None, + ) + if data is not None: + d = self._parse_socket_type(data) + return d @staticmethod async def _socket_ping(ip: str, cmd: str) -> str | None: