diff --git a/backend/tools/simple_state_checker.py b/backend/tools/simple_state_checker.py index 35c2998..62cda02 100644 --- a/backend/tools/simple_state_checker.py +++ b/backend/tools/simple_state_checker.py @@ -87,7 +87,7 @@ def notify_users_of_problem(msg: str): pass -def get_recorder_adapter(recorder_info:dict) -> RecorderAdapter: +def get_recorder_adapter(recorder_info: dict) -> RecorderAdapter: if "SMP" in recorder_info["type"]: rec = SMP(recorder_info['ip'], recorder_info['password']) else: @@ -131,13 +131,17 @@ def check_capture_agent_state(a: dict): agents = get_capture_agents() logger.info("Got {} capture agents that will be checked...".format(len(agents))) -#pool = ThreadPool(5) -#pool.map(check_capture_agent_state, agents) +# pool = ThreadPool(5) +# pool.map(check_capture_agent_state, agents) -with ThreadPool(5) as pool: - for agent in agents: - pool.apply_async(check_capture_agent_state, agent).get(timeout=10) # start single threads and enforce timeout +NUM_THREADS = 5 +with ThreadPool(NUM_THREADS) as pool: + results = [pool.apply_async(check_capture_agent_state, (agent,)) for agent in agents] + try: + [res.get(timeout=12) for res in results] + except TimeoutError: + logger.error("Timeout while getting capture agent state!") pool.close() pool.join()