From 624f948f549496b4366cb620393b69cc9427f038 Mon Sep 17 00:00:00 2001 From: baskiton Date: Mon, 23 Sep 2024 18:15:27 +0700 Subject: [PATCH] run gr_decoder on separate process --- tools/client_server/gr_decoder.py | 21 +++++++++++++++++++++ tools/client_server/server.py | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tools/client_server/gr_decoder.py b/tools/client_server/gr_decoder.py index 52884be..ddfc8df 100644 --- a/tools/client_server/gr_decoder.py +++ b/tools/client_server/gr_decoder.py @@ -163,3 +163,24 @@ def process(fp: pathlib.Path, params: dict): x = executor.action() print(x) + + +def _process(fp: pathlib.Path, params: dict, q: mp.Queue = None): + logger = logging.getLogger() + logger.handlers.clear() + logger.setLevel(mp.get_logger().level) + if q is not None: + qh = logging.handlers.QueueHandler(q) + logger.addHandler(qh) + log = logging.getLogger('GRProcess') + + try: + process(fp, params) + except: + log.error('process error:', exc_info=True) + + +def process2(fp: pathlib.Path, params: dict, log: logging.Logger = None): + p = mp.Process(target=_process, args=(fp, params, log)) + p.start() + p.join() diff --git a/tools/client_server/server.py b/tools/client_server/server.py index eb69226..89f6377 100644 --- a/tools/client_server/server.py +++ b/tools/client_server/server.py @@ -188,7 +188,7 @@ def action(self): try: self.log.info('Decode processing') - gr_decoder.process(fp, params) + gr_decoder.process2(fp, params, self.q) except: self.log.error('gr_decoder')