refs #806 join threads when a new operation is requested

pull/10/head
Natalia Serrano 2024-10-03 14:39:31 +02:00
parent 72e4198762
commit 068e0cf633
3 changed files with 24 additions and 13 deletions

View File

@ -170,19 +170,8 @@ class CloningEngineWorker (ogLiveWorker):
return self.respuestaEjecucionComando (cmd, herror, ids) return self.respuestaEjecucionComando (cmd, herror, ids)
def process_status (self, path, get_params, post_params, server): def process_status (self, path, get_params, post_params, server):
## join finished threads self._join_threads()
for k in self.thread_list:
logger.debug (f'considering thread ({k})')
elem = self.thread_list[k]
if 'thread' in elem:
elem['thread'].join (0.05)
if not elem['thread'].is_alive():
logger.debug (f'is no longer alive, k ({k}) thread ({elem["thread"]})')
elem['running'] = False
elem['result'] = elem['thread'].result
del elem['thread']
## return status of threads
thr_status = {} thr_status = {}
for k in self.thread_list: for k in self.thread_list:
thr_status[k] = { thr_status[k] = {

View File

@ -385,7 +385,15 @@ class ogAdmClientWorker (ogLiveWorker):
@check_secret @check_secret
def process_status (self, path, get_params, post_params, server): def process_status (self, path, get_params, post_params, server):
return {self.name: 'in process_status'} ## XXX self._join_threads()
thr_status = {}
for k in self.thread_list:
thr_status[k] = {
'running': self.thread_list[k]['running'],
'result': self.thread_list[k]['result'],
}
return thr_status
@check_secret @check_secret
def process_popup (self, path, get_params, post_params, server): def process_popup (self, path, get_params, post_params, server):

View File

@ -194,6 +194,8 @@ class ogLiveWorker(ServerWorker):
raise Exception ('Se han generado errores. No se puede continuar la ejecución de este módulo') raise Exception ('Se han generado errores. No se puede continuar la ejecución de este módulo')
def _long_running_job (self, name, f, args): def _long_running_job (self, name, f, args):
self._join_threads()
any_job_running = False any_job_running = False
for k in self.thread_list: for k in self.thread_list:
if self.thread_list[k]['running']: if self.thread_list[k]['running']:
@ -212,3 +214,15 @@ class ogLiveWorker(ServerWorker):
} }
self.thread_list[job_id]['thread'].start() self.thread_list[job_id]['thread'].start()
return { 'job_id': job_id } return { 'job_id': job_id }
def _join_threads (self):
for k in self.thread_list:
logger.debug (f'considering thread ({k})')
elem = self.thread_list[k]
if 'thread' in elem:
elem['thread'].join (0.05)
if not elem['thread'].is_alive():
logger.debug (f'is no longer alive, k ({k}) thread ({elem["thread"]})')
elem['running'] = False
elem['result'] = elem['thread'].result
del elem['thread']