From 7098d5525870f6f6b77e3706d61a785ccc6149f3 Mon Sep 17 00:00:00 2001 From: zhayujie Date: Wed, 22 Mar 2023 01:19:18 +0800 Subject: [PATCH] fix: code optimization --- app.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/app.py b/app.py index 72764b0..221a83e 100644 --- a/app.py +++ b/app.py @@ -38,26 +38,25 @@ if __name__ == '__main__': exit(0) # 3.多通道配置时,进程池启动 + # 使用主进程启动终端通道 + if const.TERMINAL in channel_type: + index = channel_type.index(const.TERMINAL) + terminal = channel_type.pop(index) else: - # 使用主进程启动终端通道 - if const.TERMINAL in channel_type: - index = channel_type.index(const.TERMINAL) - terminal = channel_type.pop(index) - else: - terminal = None + terminal = None - # 使用进程池启动其他通道子进程 - pool = Pool(len(channel_type)) - for type_item in channel_type: - log.info("[INIT] Start up: {} on {}", model_type, type_item) - pool.apply_async(start_process, args=[type_item]) + # 使用进程池启动其他通道子进程 + pool = Pool(len(channel_type)) + for type_item in channel_type: + log.info("[INIT] Start up: {} on {}", model_type, type_item) + pool.apply_async(start_process, args=[type_item]) - if terminal: - start_process(terminal) + if terminal: + start_process(terminal) - # 等待池中所有进程执行完毕 - pool.close() - pool.join() + # 等待池中所有进程执行完毕 + pool.close() + pool.join() except Exception as e: log.error("App startup failed!") log.exception(e)