From c65e4911b32ca114eed9ba701d260c09adce2540 Mon Sep 17 00:00:00 2001 From: dnomd343 Date: Mon, 8 Aug 2022 16:18:23 +0800 Subject: [PATCH] feat: add check thread option --- Basis/Constant.py | 2 ++ main.py | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Basis/Constant.py b/Basis/Constant.py index b0673b9..d30ef82 100644 --- a/Basis/Constant.py +++ b/Basis/Constant.py @@ -11,6 +11,8 @@ ApiPath = '/' ApiPort = 7839 ApiToken = '' +CheckThread = 64 + LogLevel = 'INFO' LogFile = 'runtime.log' diff --git a/main.py b/main.py index 89f3c34..fa104fb 100755 --- a/main.py +++ b/main.py @@ -18,6 +18,7 @@ def mainArgParse(rawArgs: list) -> argparse.Namespace: mainParser.add_argument('--port', type = int, default = Constant.ApiPort, help = 'port for running') mainParser.add_argument('--path', type = str, default = Constant.ApiPath, help = 'root path for api server') mainParser.add_argument('--token', type = str, default = Constant.ApiToken, help = 'token for api server') + mainParser.add_argument('--thread', type = int, default = Constant.CheckThread, help = 'number of check thread') mainParser.add_argument('-v', '--version', help = 'show version', action = 'store_true') return mainParser.parse_args(rawArgs) @@ -96,7 +97,8 @@ def runCheck(taskId: str, taskInfo: dict) -> None: Manager.finishTask(taskId, checkResult) # commit check result -def loop(threadNum: int = 16) -> None: +def loop(threadNum: int) -> None: + logging.warning('Loop check start -> %i threads' % threadNum) threadPool = ThreadPoolExecutor(max_workers = threadNum) # init thread pool while True: try: @@ -133,5 +135,5 @@ if testMode: # test mode logging.warning('ProxyC starts running (%s)' % Constant.Version) _thread.start_new_thread(pythonCompile, ('/usr',)) # python compile (generate .pyc file) _thread.start_new_thread(DnsProxy.start, (Constant.DnsServer, 53)) # start dns server -_thread.start_new_thread(loop, ()) # start check loop +_thread.start_new_thread(loop, (Constant.CheckThread, )) # start check loop Api.startServer() # start api server