Index: gc_lang/fr/config.ini ================================================================== --- gc_lang/fr/config.ini +++ gc_lang/fr/config.ini @@ -4,11 +4,11 @@ locales = fr_FR fr_BE fr_CA fr_CH fr_LU fr_BF fr_BJ fr_CD fr_CI fr_CM fr_MA fr_ML fr_MU fr_NE fr_RE fr_SN fr_TG country_default = FR name = Grammalecte implname = grammalecte # always use 3 numbers for version: x.y.z -version = 1.3.0 +version = 1.3.1 author = Olivier R. provider = Grammalecte.net link = https://grammalecte.net description = Correcteur grammatical pour le français. extras = README_fr.txt Index: grammalecte-server.py ================================================================== --- grammalecte-server.py +++ grammalecte-server.py @@ -24,26 +24,10 @@ oGrammarChecker = grammalecte.GrammarChecker("fr", "Server") oSpellChecker = oGrammarChecker.getSpellChecker() oTextFormatter = oGrammarChecker.getTextFormatter() oGCE = oGrammarChecker.getGCEngine() - -xProcessPoolExecutor = None - - -def initExecutor (nMultiCPU=None): - "process pool executor initialisation" - global xProcessPoolExecutor - if xProcessPoolExecutor: - # we shutdown the ProcessPoolExecutor which may have been launched previously - xProcessPoolExecutor.shutdown(wait=False) - 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' sDataJSON = "" @@ -72,10 +56,27 @@ return '{"suggestions": ' + json.dumps(lSugg, ensure_ascii=False) + '}' except json.JSONDecodeError: return '{"error": "json encoding error"}' return '{"error": "no token given"}' + +#### PROCESS POOL EXECUTOR #### +xProcessPoolExecutor = None + +def initExecutor (nMultiCPU=None): + "process pool executor initialisation" + global xProcessPoolExecutor + if xProcessPoolExecutor: + # we shutdown the ProcessPoolExecutor which may have been launched previously + print("ProcessPoolExecutor shutdown.") + xProcessPoolExecutor.shutdown(wait=False) + 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) + #### SERVEUR #### HOMEPAGE = """ @@ -351,8 +352,8 @@ xArgs.port or 8080, \ dOpt, xArgs.test_page, xArgs.multiprocessor) else: - # we do it for the server may be used with WSGI (which doesn’t call main()) + # Must be launched at start, for WSGI server (which doesn’t call main()) # WSGI servers just import the given file as a module and use an object exported from it ( in this case) to run the server. initExecutor()