modified threadpool run to use timeout

This commit is contained in:
2019-11-14 14:56:55 +01:00
parent c96cdfc6e1
commit 7224038e64
2 changed files with 9 additions and 8 deletions

View File

@@ -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:

View File

@@ -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()