Browse Source

feat: add check thread option

master^2
dnomd343 2 years ago
parent
commit
c65e4911b3
  1. 2
      Basis/Constant.py
  2. 6
      main.py

2
Basis/Constant.py

@ -11,6 +11,8 @@ ApiPath = '/'
ApiPort = 7839 ApiPort = 7839
ApiToken = '' ApiToken = ''
CheckThread = 64
LogLevel = 'INFO' LogLevel = 'INFO'
LogFile = 'runtime.log' LogFile = 'runtime.log'

6
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('--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('--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('--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') mainParser.add_argument('-v', '--version', help = 'show version', action = 'store_true')
return mainParser.parse_args(rawArgs) return mainParser.parse_args(rawArgs)
@ -96,7 +97,8 @@ def runCheck(taskId: str, taskInfo: dict) -> None:
Manager.finishTask(taskId, checkResult) # commit check result 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 threadPool = ThreadPoolExecutor(max_workers = threadNum) # init thread pool
while True: while True:
try: try:
@ -133,5 +135,5 @@ if testMode: # test mode
logging.warning('ProxyC starts running (%s)' % Constant.Version) logging.warning('ProxyC starts running (%s)' % Constant.Version)
_thread.start_new_thread(pythonCompile, ('/usr',)) # python compile (generate .pyc file) _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(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 Api.startServer() # start api server

Loading…
Cancel
Save