Index: grammalecte-server.py ================================================================== --- grammalecte-server.py +++ grammalecte-server.py @@ -28,17 +28,18 @@ xProcessPoolExecutor = None -def initExecutor (nCore=None): +def initExecutor (nMultiCPU=None): "process pool executor initialisation" global xProcessPoolExecutor - if nCore is None: - nCore = max(os.cpu_count()-1, 1) - print("CPU processes used for workers: ", nCore) - xProcessPoolExecutor = concurrent.futures.ProcessPoolExecutor(max_workers=nCore) + nMaxCPU = max(os.cpu_count()-1, 1) + if nMultiCPU is None or not (1 <= nMultiCPU <= nMaxCPU): + nMultiCPU = nMaxCPU + print("CPU processes used for workers: ", nMultiCPU) + xProcessPoolExecutor = concurrent.futures.ProcessPoolExecutor(max_workers=nMultiCPU) def parseText (sText, dOptions=None, bFormatText=False, sError=""): "parse and return errors in a JSON format" sJSON = '{ "program": "grammalecte-fr", "version": "'+oGCE.version+'", "lang": "'+oGCE.lang+'", "error": "'+sError+'", "data" : [\n' @@ -294,11 +295,11 @@ return False #### START #### -def main (sHost="localhost", nPort=8080, dOptions=None, bTestPage=False, nMultiProc=None): +def main (sHost="localhost", nPort=8080, dOptions=None, bTestPage=False, nMultiCPU=None): "start server" global TESTPAGE global HOMEPAGE if bTestPage: @@ -305,14 +306,18 @@ TESTPAGE = True HOMEPAGE = HOMEPAGE.replace("{SERVER_PORT}", str(nPort)) if dOptions: oGCE.setOptions(dOptions) + # Python version print("Python: " + sys.version) + # Grammalecte echo("Grammalecte v{}".format(oGCE.version)) oGCE.displayOptions() - initExecutor() + # Process Pool Executor + initExecutor(nMultiCPU) + # Server (Bottle) run(app, host=sHost, port=nPort) if __name__ == '__main__': xParser = argparse.ArgumentParser() @@ -331,12 +336,10 @@ if xArgs.opt_on: dOpt = { opt:True for opt in xArgs.opt_on } if xArgs.opt_off: dOpt.update({ opt:False for opt in xArgs.opt_off }) - print(xArgs.multiprocessor) - main(xArgs.host or "localhost", \ xArgs.port or 8080, \ dOpt, xArgs.test_page, xArgs.multiprocessor)