Grammalecte  Diff

Differences From Artifact [800ce882b1]:

To Artifact [38ce8a200e]:


    22     22   #### GRAMMAR CHECKER ####
    23     23   
    24     24   oGrammarChecker = grammalecte.GrammarChecker("fr", "Server")
    25     25   oSpellChecker = oGrammarChecker.getSpellChecker()
    26     26   oTextFormatter = oGrammarChecker.getTextFormatter()
    27     27   oGCE = oGrammarChecker.getGCEngine()
    28     28   
    29         -
    30         -xProcessPoolExecutor = None
    31         -
    32         -
    33         -def initExecutor (nMultiCPU=None):
    34         -    "process pool executor initialisation"
    35         -    global xProcessPoolExecutor
    36         -    if xProcessPoolExecutor:
    37         -        # we shutdown the ProcessPoolExecutor which may have been launched previously
    38         -        xProcessPoolExecutor.shutdown(wait=False)
    39         -    nMaxCPU = max(os.cpu_count()-1, 1)
    40         -    if nMultiCPU is None or not (1 <= nMultiCPU <= nMaxCPU):
    41         -        nMultiCPU = nMaxCPU
    42         -    print("CPU processes used for workers: ", nMultiCPU)
    43         -    xProcessPoolExecutor = concurrent.futures.ProcessPoolExecutor(max_workers=nMultiCPU)
    44         -
    45     29   
    46     30   def parseText (sText, dOptions=None, bFormatText=False, sError=""):
    47     31       "parse <sText> and return errors in a JSON format"
    48     32       sJSON = '{ "program": "grammalecte-fr", "version": "'+oGCE.version+'", "lang": "'+oGCE.lang+'", "error": "'+sError+'", "data" : [\n'
    49     33       sDataJSON = ""
    50     34       for i, sParagraph in enumerate(txt.getParagraph(sText), 1):
    51     35           if bFormatText:
................................................................................
    70     54               return '{"error": "suggestion module failed"}'
    71     55           try:
    72     56               return '{"suggestions": ' + json.dumps(lSugg, ensure_ascii=False) + '}'
    73     57           except json.JSONDecodeError:
    74     58               return '{"error": "json encoding error"}'
    75     59       return '{"error": "no token given"}'
    76     60   
           61  +
           62  +#### PROCESS POOL EXECUTOR ####
           63  +xProcessPoolExecutor = None
           64  +
           65  +def initExecutor (nMultiCPU=None):
           66  +    "process pool executor initialisation"
           67  +    global xProcessPoolExecutor
           68  +    if xProcessPoolExecutor:
           69  +        # we shutdown the ProcessPoolExecutor which may have been launched previously
           70  +        print("ProcessPoolExecutor shutdown.")
           71  +        xProcessPoolExecutor.shutdown(wait=False)
           72  +    nMaxCPU = max(os.cpu_count()-1, 1)
           73  +    if nMultiCPU is None or not (1 <= nMultiCPU <= nMaxCPU):
           74  +        nMultiCPU = nMaxCPU
           75  +    print("CPU processes used for workers: ", nMultiCPU)
           76  +    xProcessPoolExecutor = concurrent.futures.ProcessPoolExecutor(max_workers=nMultiCPU)
           77  +
    77     78   
    78     79   #### SERVEUR ####
    79     80   
    80     81   HOMEPAGE = """
    81     82   <!DOCTYPE HTML>
    82     83   <html>
    83     84       <head>
................................................................................
   349    350   
   350    351       main(xArgs.host or "localhost", \
   351    352            xArgs.port or 8080, \
   352    353            dOpt,
   353    354            xArgs.test_page,
   354    355            xArgs.multiprocessor)
   355    356   else:
   356         -    # we do it for the server may be used with WSGI (which doesn’t call main())
          357  +    # Must be launched at start, for WSGI server (which doesn’t call main())
   357    358       # WSGI servers just import the given file as a module and use an object exported from it (<app> in this case) to run the server.
   358    359       initExecutor()