From 068e0cf63327d08f12fbe1217b9519b6ba5d512e Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Thu, 3 Oct 2024 14:39:31 +0200 Subject: [PATCH] refs #806 join threads when a new operation is requested --- .../modules/server/CloningEngine/__init__.py | 13 +------------ .../modules/server/ogAdmClient/__init__.py | 10 +++++++++- src/opengnsys/workers/oglive_worker.py | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/opengnsys/modules/server/CloningEngine/__init__.py b/src/opengnsys/modules/server/CloningEngine/__init__.py index ac9ac2c..ac93cf9 100644 --- a/src/opengnsys/modules/server/CloningEngine/__init__.py +++ b/src/opengnsys/modules/server/CloningEngine/__init__.py @@ -170,19 +170,8 @@ class CloningEngineWorker (ogLiveWorker): return self.respuestaEjecucionComando (cmd, herror, ids) def process_status (self, path, get_params, post_params, server): - ## join finished 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'] + self._join_threads() - ## return status of threads thr_status = {} for k in self.thread_list: thr_status[k] = { diff --git a/src/opengnsys/modules/server/ogAdmClient/__init__.py b/src/opengnsys/modules/server/ogAdmClient/__init__.py index 98ca5c8..d1c918a 100644 --- a/src/opengnsys/modules/server/ogAdmClient/__init__.py +++ b/src/opengnsys/modules/server/ogAdmClient/__init__.py @@ -385,7 +385,15 @@ class ogAdmClientWorker (ogLiveWorker): @check_secret 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 def process_popup (self, path, get_params, post_params, server): diff --git a/src/opengnsys/workers/oglive_worker.py b/src/opengnsys/workers/oglive_worker.py index 1232e49..8fb02e9 100644 --- a/src/opengnsys/workers/oglive_worker.py +++ b/src/opengnsys/workers/oglive_worker.py @@ -194,6 +194,8 @@ class ogLiveWorker(ServerWorker): 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): + self._join_threads() + any_job_running = False for k in self.thread_list: if self.thread_list[k]['running']: @@ -212,3 +214,15 @@ class ogLiveWorker(ServerWorker): } self.thread_list[job_id]['thread'].start() 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']