From 5c766b15553db804e8f3404adca987155dc5149a Mon Sep 17 00:00:00 2001 From: Eduard Carreras Date: Wed, 21 Feb 2024 17:16:46 +0100 Subject: [PATCH 1/2] Convert RES4667 to StopMultiProcess --- libcnmc/res_4667/CT.py | 12 +++++++----- libcnmc/res_4667/DES.py | 12 +++++++----- libcnmc/res_4667/FIA.py | 12 +++++++----- libcnmc/res_4667/LAT.py | 12 +++++++----- libcnmc/res_4667/LBT.py | 12 +++++++----- libcnmc/res_4667/MACRO.py | 12 +++++++----- libcnmc/res_4667/MAQ.py | 11 +++++++---- libcnmc/res_4667/Otros.py | 12 +++++++----- libcnmc/res_4667/POS.py | 10 +++++++--- libcnmc/res_4667/PRO.py | 12 +++++++----- libcnmc/res_4667/RES.py | 12 +++++++----- libcnmc/res_4667/RES_CCAA.py | 11 +++++++---- 12 files changed, 84 insertions(+), 56 deletions(-) diff --git a/libcnmc/res_4667/CT.py b/libcnmc/res_4667/CT.py index 548690e5..8ca48958 100644 --- a/libcnmc/res_4667/CT.py +++ b/libcnmc/res_4667/CT.py @@ -8,10 +8,10 @@ from libcnmc.res_4667.utils import get_resum_any_id from libcnmc.utils import format_f, get_name_ti, get_codigo_ccaa -from libcnmc.core import MultiprocessBased +from libcnmc.core import StopMultiprocessBased -class CT(MultiprocessBased): +class CT(StopMultiprocessBased): """ Class to generate F6 of 4667 """ @@ -57,6 +57,9 @@ def consumer(self): while True: try: item = self.input_q.get() + if item == "STOP": + self.input_q.task_done() + break self.progress_q.put(item) ct = O.GiscedataCnmcCt.read(item, fields_to_read) @@ -76,10 +79,9 @@ def consumer(self): ct["actuacio_elegible_prtr"] or '', ] self.output_q.put(output) - + self.input_q.task_done() except Exception: + self.input_q.task_done() traceback.print_exc() if self.raven: self.raven.captureException() - finally: - self.input_q.task_done() diff --git a/libcnmc/res_4667/DES.py b/libcnmc/res_4667/DES.py index 12c78f74..5ddd5c14 100644 --- a/libcnmc/res_4667/DES.py +++ b/libcnmc/res_4667/DES.py @@ -8,10 +8,10 @@ from libcnmc.res_4667.utils import get_resum_any_id from libcnmc.utils import get_name_ti, get_codigo_ccaa, format_f -from libcnmc.core import MultiprocessBased +from libcnmc.core import StopMultiprocessBased -class DES(MultiprocessBased): +class DES(StopMultiprocessBased): """ Class to generate F6 of 4667 """ @@ -57,6 +57,9 @@ def consumer(self): while True: try: item = self.input_q.get() + if item == "STOP": + self.input_q.task_done() + break self.progress_q.put(item) des = O.GiscedataCnmcDespatx.read(item, fields_to_read) @@ -74,10 +77,9 @@ def consumer(self): des["actuacio_elegible_prtr"] or '', ] self.output_q.put(output) - + self.input_q.task_done() except Exception: + self.input_q.task_done() traceback.print_exc() if self.raven: self.raven.captureException() - finally: - self.input_q.task_done() diff --git a/libcnmc/res_4667/FIA.py b/libcnmc/res_4667/FIA.py index a42de861..17528e8a 100644 --- a/libcnmc/res_4667/FIA.py +++ b/libcnmc/res_4667/FIA.py @@ -8,10 +8,10 @@ from libcnmc.res_4667.utils import get_resum_any_id from libcnmc.utils import format_f, get_codigo_ccaa, get_name_ti -from libcnmc.core import MultiprocessBased +from libcnmc.core import StopMultiprocessBased -class FIA(MultiprocessBased): +class FIA(StopMultiprocessBased): """ Class to generate F6 of 4667 """ @@ -58,6 +58,9 @@ def consumer(self): while True: try: item = self.input_q.get() + if item == "STOP": + self.input_q.task_done() + break self.progress_q.put(item) fia = O.GiscedataCnmcFiabilitat.read(item, fields_to_read) @@ -77,10 +80,9 @@ def consumer(self): fia["actuacio_elegible_prtr"] or '', ] self.output_q.put(output) - + self.input_q.task_done() except Exception: + self.input_q.task_done() traceback.print_exc() if self.raven: self.raven.captureException() - finally: - self.input_q.task_done() diff --git a/libcnmc/res_4667/LAT.py b/libcnmc/res_4667/LAT.py index faf1fc5a..f72b6179 100644 --- a/libcnmc/res_4667/LAT.py +++ b/libcnmc/res_4667/LAT.py @@ -8,10 +8,10 @@ from libcnmc.res_4667.utils import get_resum_any_id from libcnmc.utils import get_name_ti, get_codigo_ccaa, format_f -from libcnmc.core import MultiprocessBased +from libcnmc.core import StopMultiprocessBased -class LAT(MultiprocessBased): +class LAT(StopMultiprocessBased): """ Class to generate F1 of 4667 """ @@ -54,6 +54,9 @@ def consumer(self): while True: try: item = self.input_q.get() + if item == "STOP": + self.input_q.task_done() + break self.progress_q.put(item) linia = O.GiscedataCnmcLinies.read(item, fields_to_read) @@ -86,10 +89,9 @@ def consumer(self): linia["actuacio_elegible_prtr"] or '', ] self.output_q.put(output) - + self.input_q.task_done() except Exception: + self.input_q.task_done() traceback.print_exc() if self.raven: self.raven.captureException() - finally: - self.input_q.task_done() diff --git a/libcnmc/res_4667/LBT.py b/libcnmc/res_4667/LBT.py index 60335a10..1af43a4c 100644 --- a/libcnmc/res_4667/LBT.py +++ b/libcnmc/res_4667/LBT.py @@ -3,12 +3,12 @@ import traceback -from libcnmc.core import MultiprocessBased +from libcnmc.core import StopMultiprocessBased from libcnmc.res_4667.utils import get_resum_any_id from libcnmc.utils import get_codigo_ccaa, get_name_ti, format_f -class LBT(MultiprocessBased): +class LBT(StopMultiprocessBased): """ Class to generate F2 of 4667 """ @@ -52,6 +52,9 @@ def consumer(self): while True: try: item = self.input_q.get() + if item == "STOP": + self.input_q.task_done() + break self.progress_q.put(item) lbt = O.GiscedataCnmcLiniesbt.read(item, fields_to_read) @@ -74,10 +77,9 @@ def consumer(self): lbt["actuacio_elegible_prtr"] or '', ] self.output_q.put(output) - + self.input_q.task_done() except Exception: + self.input_q.task_done() traceback.print_exc() if self.raven: self.raven.captureException() - finally: - self.input_q.task_done() diff --git a/libcnmc/res_4667/MACRO.py b/libcnmc/res_4667/MACRO.py index f09e668c..8db38603 100644 --- a/libcnmc/res_4667/MACRO.py +++ b/libcnmc/res_4667/MACRO.py @@ -4,11 +4,11 @@ import traceback from libcnmc.res_4667.utils import get_resum_any_id -from libcnmc.core import MultiprocessBased +from libcnmc.core import StopMultiprocessBased from libcnmc.utils import format_f -class MACRO(MultiprocessBased): +class MACRO(StopMultiprocessBased): """ Class to generate F2 of 4667 """ @@ -49,6 +49,9 @@ def consumer(self): while True: try: item = self.input_q.get() + if item == "STOP": + self.input_q.task_done() + break self.progress_q.put(item) macro = O.GiscedataCnmcResum_any.read(item, fields_to_read) @@ -60,10 +63,9 @@ def consumer(self): format_f(float(macro["macro_inc_demanda_sector"]), 2) or "0.00" ] self.output_q.put(output) - + self.input_q.task_done() except Exception: + self.input_q.task_done() traceback.print_exc() if self.raven: self.raven.captureException() - finally: - self.input_q.task_done() diff --git a/libcnmc/res_4667/MAQ.py b/libcnmc/res_4667/MAQ.py index 92d78397..f70b5979 100644 --- a/libcnmc/res_4667/MAQ.py +++ b/libcnmc/res_4667/MAQ.py @@ -5,10 +5,10 @@ from libcnmc.res_4667.utils import get_resum_any_id from libcnmc.utils import format_f, get_name_ti, get_codigo_ccaa -from libcnmc.core import MultiprocessBased +from libcnmc.core import StopMultiprocessBased -class MAQ(MultiprocessBased): +class MAQ(StopMultiprocessBased): """ Class to generate F5 of 4667 """ @@ -54,6 +54,9 @@ def consumer(self): while True: try: item = self.input_q.get() + if item == "STOP": + self.input_q.task_done() + break self.progress_q.put(item) maq = O.GiscedataCnmcMaquines.read(item, fields_to_read) @@ -74,9 +77,9 @@ def consumer(self): maq["actuacio_elegible_prtr"] or '', ] self.output_q.put(output) + self.input_q.task_done() except Exception: + self.input_q.task_done() traceback.print_exc() if self.raven: self.raven.captureException() - finally: - self.input_q.task_done() diff --git a/libcnmc/res_4667/Otros.py b/libcnmc/res_4667/Otros.py index 17446118..a325bdfc 100644 --- a/libcnmc/res_4667/Otros.py +++ b/libcnmc/res_4667/Otros.py @@ -5,10 +5,10 @@ from libcnmc.res_4667.utils import get_resum_any_id from libcnmc.utils import get_codigo_ccaa, format_f -from libcnmc.core import MultiprocessBased +from libcnmc.core import StopMultiprocessBased -class Otros(MultiprocessBased): +class Otros(StopMultiprocessBased): """ Class to generate F3 of 4667 """ @@ -51,6 +51,9 @@ def consumer(self): while True: try: item = self.input_q.get() + if item == "STOP": + self.input_q.task_done() + break self.progress_q.put(item) otro = O.GiscedataCnmcAltres.read(item, fields_to_read) @@ -69,10 +72,9 @@ def consumer(self): otro["actuacio_elegible_prtr"] or '', ] self.output_q.put(output) - + self.input_q.task_done() except Exception: + self.input_q.task_done() traceback.print_exc() if self.raven: self.raven.captureException() - finally: - self.input_q.task_done() diff --git a/libcnmc/res_4667/POS.py b/libcnmc/res_4667/POS.py index 1aa5cf3a..8d9ddd53 100644 --- a/libcnmc/res_4667/POS.py +++ b/libcnmc/res_4667/POS.py @@ -6,9 +6,10 @@ from libcnmc.res_4667.utils import get_resum_any_id from libcnmc.utils import format_f, get_name_ti, get_codigo_ccaa from libcnmc.core import MultiprocessBased +from libcnmc.core import StopMultiprocessBased -class POS(MultiprocessBased): +class POS(StopMultiprocessBased): """ Class to generate F5 of 4667 """ @@ -53,6 +54,9 @@ def consumer(self): while True: try: item = self.input_q.get() + if item == "STOP": + self.input_q.task_done() + break self.progress_q.put(item) pos = O.GiscedataCnmcPosicions.read(item, fields_to_read) @@ -72,9 +76,9 @@ def consumer(self): pos["actuacio_elegible_prtr"] or '', ] self.output_q.put(output) + self.input_q.task_done() except Exception: + self.input_q.task_done() traceback.print_exc() if self.raven: self.raven.captureException() - finally: - self.input_q.task_done() diff --git a/libcnmc/res_4667/PRO.py b/libcnmc/res_4667/PRO.py index 47e622f3..f100e8d8 100644 --- a/libcnmc/res_4667/PRO.py +++ b/libcnmc/res_4667/PRO.py @@ -5,10 +5,10 @@ from libcnmc.res_4667.utils import get_resum_any_id from libcnmc.utils import format_f, get_codigo_ccaa -from libcnmc.core import MultiprocessBased +from libcnmc.core import StopMultiprocessBased -class PRO(MultiprocessBased): +class PRO(StopMultiprocessBased): """ Class to generate proyectos of 4667 """ @@ -87,6 +87,9 @@ def consumer(self): while True: try: item = self.input_q.get() + if item == "STOP": + self.input_q.task_done() + break self.progress_q.put(item) pro = O.GiscedataCnmcProjectes.read(item, fields_to_read) codigo = pro["codi"] @@ -110,11 +113,10 @@ def consumer(self): pro["estado"] ] - self.output_q.put(output) + self.input_q.task_done() except Exception: + self.input_q.task_done() traceback.print_exc() if self.raven: self.raven.captureException() - finally: - self.input_q.task_done() diff --git a/libcnmc/res_4667/RES.py b/libcnmc/res_4667/RES.py index fa1916e5..249e1cdb 100644 --- a/libcnmc/res_4667/RES.py +++ b/libcnmc/res_4667/RES.py @@ -5,10 +5,10 @@ from libcnmc.res_4667.utils import get_resum_any_id from libcnmc.utils import format_f -from libcnmc.core import MultiprocessBased +from libcnmc.core import StopMultiprocessBased -class RES(MultiprocessBased): +class RES(StopMultiprocessBased): """ Class to generate F2 of 4667 """ @@ -70,6 +70,9 @@ def consumer(self): while True: try: item = self.input_q.get() + if item == "STOP": + self.input_q.task_done() + break self.progress_q.put(item) resumen = O.GiscedataCnmcResum_any.read(item, fields_to_read) @@ -100,10 +103,9 @@ def consumer(self): resumen["num_proyectos_prtr"] or "0", ] self.output_q.put(output) - + self.input_q.task_done() except Exception: + self.input_q.task_done() traceback.print_exc() if self.raven: self.raven.captureException() - finally: - self.input_q.task_done() diff --git a/libcnmc/res_4667/RES_CCAA.py b/libcnmc/res_4667/RES_CCAA.py index 2e1c4a50..6265cf79 100644 --- a/libcnmc/res_4667/RES_CCAA.py +++ b/libcnmc/res_4667/RES_CCAA.py @@ -5,10 +5,10 @@ from libcnmc.res_4667.utils import get_resum_any_id from libcnmc.utils import format_f, get_codigo_ccaa -from libcnmc.core import MultiprocessBased +from libcnmc.core import StopMultiprocessBased -class RESCCAA(MultiprocessBased): +class RESCCAA(StopMultiprocessBased): """ Class to generate F2 of 4667 """ @@ -44,6 +44,9 @@ def consumer(self): :rtype: str """ item = self.input_q.get() + if item == "STOP": + self.input_q.task_done() + return self.progress_q.put(item) fields_read = [ @@ -82,9 +85,9 @@ def consumer(self): resum["num_proyectos_prtr"] or "0", ] self.output_q.put(output) + self.input_q.task_done() except Exception: + self.input_q.task_done() traceback.print_exc() if self.raven: self.raven.captureException() - finally: - self.input_q.task_done() From 5b8b9a6ef2790650bee8cdae1c1259b9ada6dbcb Mon Sep 17 00:00:00 2001 From: Eduard Carreras Date: Wed, 21 Feb 2024 17:41:06 +0100 Subject: [PATCH 2/2] Fix RES4667 CCAA --- libcnmc/res_4667/RES_CCAA.py | 62 +++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/libcnmc/res_4667/RES_CCAA.py b/libcnmc/res_4667/RES_CCAA.py index 6265cf79..9f0a4f43 100644 --- a/libcnmc/res_4667/RES_CCAA.py +++ b/libcnmc/res_4667/RES_CCAA.py @@ -43,11 +43,6 @@ def consumer(self): :return: Line :rtype: str """ - item = self.input_q.get() - if item == "STOP": - self.input_q.task_done() - return - self.progress_q.put(item) fields_read = [ "anio_periodo", @@ -66,28 +61,35 @@ def consumer(self): "num_proyectos_prtr", ] model_ccaa = self.connection.GiscedataCnmcResum_ccaa - resum = model_ccaa.read(item, fields_read) - try: - output = [ - get_codigo_ccaa(self.connection, resum["codigo_ccaa"][0]), - resum["anio_periodo"], - format_f(resum["vol_total_inv_prv_ccaa"], 2) or "0.00", - format_f(resum["ayudas_prv_ccaa"], 2) or "0.00", - format_f(resum["financiacion_prv_ccaa"], 2) or "0.00", - format_f(resum["vpi_retribuible_prv_ccaa"], 2) or "0.00", - resum["num_proyectos_ccaa"], - format_f(resum["vol_total_inv_bt_prv_ccaa"], 2) or "0.00", - format_f(resum["vol_total_inv_gr_prv_ccaa"], 2) or "0.00", - format_f(resum["vol_total_inv_prv_ccaa_prtr"], 2) or "0.00", - format_f(resum["ayudas_prv_ccaa_prtr"], 2) or "0.00", - format_f(resum["financiacion_prv_ccaa_prtr"], 2) or "0.00", - format_f(resum["vpi_retribuible_prv_ccaa_prtr"], 2) or "0.00", - resum["num_proyectos_prtr"] or "0", - ] - self.output_q.put(output) - self.input_q.task_done() - except Exception: - self.input_q.task_done() - traceback.print_exc() - if self.raven: - self.raven.captureException() + while True: + try: + item = self.input_q.get() + if item == "STOP": + self.input_q.task_done() + break + self.progress_q.put(item) + resum = model_ccaa.read(item, fields_read) + + output = [ + get_codigo_ccaa(self.connection, resum["codigo_ccaa"][0]), + resum["anio_periodo"], + format_f(resum["vol_total_inv_prv_ccaa"], 2) or "0.00", + format_f(resum["ayudas_prv_ccaa"], 2) or "0.00", + format_f(resum["financiacion_prv_ccaa"], 2) or "0.00", + format_f(resum["vpi_retribuible_prv_ccaa"], 2) or "0.00", + resum["num_proyectos_ccaa"], + format_f(resum["vol_total_inv_bt_prv_ccaa"], 2) or "0.00", + format_f(resum["vol_total_inv_gr_prv_ccaa"], 2) or "0.00", + format_f(resum["vol_total_inv_prv_ccaa_prtr"], 2) or "0.00", + format_f(resum["ayudas_prv_ccaa_prtr"], 2) or "0.00", + format_f(resum["financiacion_prv_ccaa_prtr"], 2) or "0.00", + format_f(resum["vpi_retribuible_prv_ccaa_prtr"], 2) or "0.00", + resum["num_proyectos_prtr"] or "0", + ] + self.output_q.put(output) + self.input_q.task_done() + except Exception: + self.input_q.task_done() + traceback.print_exc() + if self.raven: + self.raven.captureException()