modified threadpool run to use timeout
This commit is contained in:
@@ -31,7 +31,7 @@ class SMP(TelnetAdapter, RecorderAdapter):
|
|||||||
self._login()
|
self._login()
|
||||||
|
|
||||||
def _login(self):
|
def _login(self):
|
||||||
logger.info("Connecting to {} ...".format(self.address))
|
logger.debug("Connecting to {} ...".format(self.address))
|
||||||
try:
|
try:
|
||||||
self.tn = telnetlib.Telnet(self.address)
|
self.tn = telnetlib.Telnet(self.address)
|
||||||
except TimeoutError as e:
|
except TimeoutError as e:
|
||||||
|
|||||||
@@ -100,12 +100,8 @@ def check_capture_agent_state(a: dict):
|
|||||||
c = get_calender(a['name'])
|
c = get_calender(a['name'])
|
||||||
is_recording_in_calendar = len(list(c.timeline.now())) >= 1
|
is_recording_in_calendar = len(list(c.timeline.now())) >= 1
|
||||||
if is_recording_in_calendar:
|
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":
|
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'])
|
recorder_info = get_recorder_by_name(a['name'])
|
||||||
try:
|
try:
|
||||||
rec = get_recorder_adapter(recorder_info)
|
rec = get_recorder_adapter(recorder_info)
|
||||||
@@ -135,8 +131,13 @@ 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:
|
||||||
|
for agent in agents:
|
||||||
|
pool.apply_async(check_capture_agent_state, agent).get(timeout=10) # start single threads and enforce timeout
|
||||||
|
|
||||||
|
|
||||||
pool.close()
|
pool.close()
|
||||||
pool.join()
|
pool.join()
|
||||||
|
|||||||
Reference in New Issue
Block a user