changed thread pool code again
This commit is contained in:
@@ -87,7 +87,7 @@ def notify_users_of_problem(msg: str):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def get_recorder_adapter(recorder_info:dict) -> RecorderAdapter:
|
def get_recorder_adapter(recorder_info: dict) -> RecorderAdapter:
|
||||||
if "SMP" in recorder_info["type"]:
|
if "SMP" in recorder_info["type"]:
|
||||||
rec = SMP(recorder_info['ip'], recorder_info['password'])
|
rec = SMP(recorder_info['ip'], recorder_info['password'])
|
||||||
else:
|
else:
|
||||||
@@ -131,13 +131,17 @@ def check_capture_agent_state(a: dict):
|
|||||||
agents = get_capture_agents()
|
agents = get_capture_agents()
|
||||||
logger.info("Got {} capture agents that will be checked...".format(len(agents)))
|
logger.info("Got {} capture agents that will be checked...".format(len(agents)))
|
||||||
|
|
||||||
#pool = ThreadPool(5)
|
# pool = ThreadPool(5)
|
||||||
#pool.map(check_capture_agent_state, agents)
|
# pool.map(check_capture_agent_state, agents)
|
||||||
|
|
||||||
with ThreadPool(5) as pool:
|
NUM_THREADS = 5
|
||||||
for agent in agents:
|
|
||||||
pool.apply_async(check_capture_agent_state, agent).get(timeout=10) # start single threads and enforce timeout
|
|
||||||
|
|
||||||
|
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.close()
|
||||||
pool.join()
|
pool.join()
|
||||||
|
|||||||
Reference in New Issue
Block a user