From 96801f93d1e3152f8c1c4f51f6bb86ae1c531184 Mon Sep 17 00:00:00 2001 From: UpstreamData Date: Thu, 26 May 2022 15:41:41 -0600 Subject: [PATCH] made fault lights and async generator to make them much faster --- tools/cfg_util/commands/__init__.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/tools/cfg_util/commands/__init__.py b/tools/cfg_util/commands/__init__.py index 65df6ebe..1399a877 100644 --- a/tools/cfg_util/commands/__init__.py +++ b/tools/cfg_util/commands/__init__.py @@ -3,6 +3,7 @@ from tools.cfg_util.layout import window, update_prog_bar from tools.cfg_util.tables import TableManager from tools.cfg_util.decorators import disable_buttons from settings import CFG_UTIL_CONFIG_THREADS as COMMAND_THREADS +from typing import Tuple import asyncio @@ -12,21 +13,32 @@ async def btn_light(ip_idxs: list): table_manager = TableManager() _table = window["cmd_table"].Widget iids = _table.get_children() + tasks = [] + vals = {} for idx in ip_idxs: item = _table.item(iids[idx]) ip = item["values"][0] new_light_val = not table_manager.data[ip]["Light"] - miner = await MinerFactory().get_miner(ip) - if new_light_val: - success = await miner.fault_light_on() - else: - success = await miner.fault_light_off() + tasks.append(_fault_light(ip, new_light_val)) + vals[ip] = new_light_val + + for task in asyncio.as_completed(tasks): + ip, success = await task if success: - table_manager.data[ip]["Light"] = new_light_val + table_manager.data[ip]["Light"] = vals[ip] table_manager.data[ip]["Output"] = "Fault Light command succeeded." else: table_manager.data[ip]["Output"] = "Fault Light command failed." - table_manager.update_tables() + table_manager.update_tables() + + +async def _fault_light(ip: str, on: bool) -> Tuple[str, bool]: + miner = await MinerFactory().get_miner(ip) + if on: + success = await miner.fault_light_on() + else: + success = await miner.fault_light_off() + return miner.ip, success @disable_buttons("Rebooting")