From 7224038e643356f626c1e4d0db44d7865e12e119 Mon Sep 17 00:00:00 2001 From: Tobias Kurze Date: Thu, 14 Nov 2019 14:56:55 +0100 Subject: [PATCH] modified threadpool run to use timeout --- backend/recorder_adapters/extron_smp.py | 2 +- backend/tools/simple_state_checker.py | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/backend/recorder_adapters/extron_smp.py b/backend/recorder_adapters/extron_smp.py index 630c909..1904a22 100644 --- a/backend/recorder_adapters/extron_smp.py +++ b/backend/recorder_adapters/extron_smp.py @@ -31,7 +31,7 @@ class SMP(TelnetAdapter, RecorderAdapter): self._login() def _login(self): - logger.info("Connecting to {} ...".format(self.address)) + logger.debug("Connecting to {} ...".format(self.address)) try: self.tn = telnetlib.Telnet(self.address) except TimeoutError as e: diff --git a/backend/tools/simple_state_checker.py b/backend/tools/simple_state_checker.py index 290266f..35c2998 100644 --- a/backend/tools/simple_state_checker.py +++ b/backend/tools/simple_state_checker.py @@ -100,12 +100,8 @@ def check_capture_agent_state(a: dict): c = get_calender(a['name']) is_recording_in_calendar = len(list(c.timeline.now())) >= 1 if is_recording_in_calendar: - logger.info("{} has entry in Calender and should therfor be recording... checking now!".format(a['name'])) + logger.info("{} has entry in Calender and should therefore be recording... checking now!".format(a['name'])) if a['state'] == "capturing": - logger.info( - "{} is in capturing state, so there should be an entry in the calendar of the recorder, right? -> {}".format( - a['name'], is_recording_in_calendar - )) recorder_info = get_recorder_by_name(a['name']) try: rec = get_recorder_adapter(recorder_info) @@ -135,8 +131,13 @@ 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 + pool.close() pool.join()