Grammalecte  Diff

Differences From Artifact [567790a638]:

To Artifact [b6191d794b]:


    26     26   oTextFormatter = oGrammarChecker.getTextFormatter()
    27     27   oGCE = oGrammarChecker.getGCEngine()
    28     28   
    29     29   
    30     30   xProcessPoolExecutor = None
    31     31   
    32     32   
    33         -def initExecutor (nCore=None):
           33  +def initExecutor (nMultiCPU=None):
    34     34       "process pool executor initialisation"
    35     35       global xProcessPoolExecutor
    36         -    if nCore is None:
    37         -        nCore = max(os.cpu_count()-1, 1)
    38         -    print("CPU processes used for workers: ", nCore)
    39         -    xProcessPoolExecutor = concurrent.futures.ProcessPoolExecutor(max_workers=nCore)
           36  +    nMaxCPU = max(os.cpu_count()-1, 1)
           37  +    if nMultiCPU is None or not (1 <= nMultiCPU <= nMaxCPU):
           38  +        nMultiCPU = nMaxCPU
           39  +    print("CPU processes used for workers: ", nMultiCPU)
           40  +    xProcessPoolExecutor = concurrent.futures.ProcessPoolExecutor(max_workers=nMultiCPU)
    40     41   
    41     42   
    42     43   def parseText (sText, dOptions=None, bFormatText=False, sError=""):
    43     44       "parse <sText> and return errors in a JSON format"
    44     45       sJSON = '{ "program": "grammalecte-fr", "version": "'+oGCE.version+'", "lang": "'+oGCE.lang+'", "error": "'+sError+'", "data" : [\n'
    45     46       sDataJSON = ""
    46     47       for i, sParagraph in enumerate(txt.getParagraph(sText), 1):
................................................................................
   292    293       except KeyError:
   293    294           traceback.print_exc()
   294    295           return False
   295    296   
   296    297   
   297    298   #### START ####
   298    299   
   299         -def main (sHost="localhost", nPort=8080, dOptions=None, bTestPage=False, nMultiProc=None):
          300  +def main (sHost="localhost", nPort=8080, dOptions=None, bTestPage=False, nMultiCPU=None):
   300    301       "start server"
   301    302       global TESTPAGE
   302    303       global HOMEPAGE
   303    304   
   304    305       if bTestPage:
   305    306           TESTPAGE = True
   306    307           HOMEPAGE = HOMEPAGE.replace("{SERVER_PORT}", str(nPort))
   307    308       if dOptions:
   308    309           oGCE.setOptions(dOptions)
   309    310   
          311  +    # Python version
   310    312       print("Python: " + sys.version)
          313  +    # Grammalecte
   311    314       echo("Grammalecte v{}".format(oGCE.version))
   312    315       oGCE.displayOptions()
   313         -    initExecutor()
          316  +    # Process Pool Executor
          317  +    initExecutor(nMultiCPU)
          318  +    # Server (Bottle)
   314    319       run(app, host=sHost, port=nPort)
   315    320   
   316    321   
   317    322   if __name__ == '__main__':
   318    323       xParser = argparse.ArgumentParser()
   319    324       #xParser.add_argument("lang", type=str, nargs='+', help="lang project to generate (name of folder in /lang)")
   320    325       xParser.add_argument("-ht", "--host", help="host (default: localhost)", type=str)
................................................................................
   329    334       if xArgs.opt_on  or  xArgs.opt_off:
   330    335           dOpt = {}
   331    336           if xArgs.opt_on:
   332    337               dOpt = { opt:True  for opt in xArgs.opt_on }
   333    338           if xArgs.opt_off:
   334    339               dOpt.update({ opt:False  for opt in xArgs.opt_off })
   335    340   
   336         -    print(xArgs.multiprocessor)
   337         -
   338    341       main(xArgs.host or "localhost", \
   339    342            xArgs.port or 8080, \
   340    343            dOpt,
   341    344            xArgs.test_page,
   342    345            xArgs.multiprocessor)