--- a/RadonMetrics/CodeMetricsCalculator.py Mon Sep 19 17:43:37 2022 +0200 +++ b/RadonMetrics/CodeMetricsCalculator.py Mon Sep 19 17:54:33 2022 +0200 @@ -14,7 +14,7 @@ def initService(): """ Initialize the service and return the entry point. - + @return the entry point for the background client (function) """ return rawCodeMetrics @@ -23,7 +23,7 @@ def initBatchService(): """ Initialize the batch service and return the entry point. - + @return the entry point for the background client (function) """ return batchRawCodeMetrics @@ -32,7 +32,7 @@ def rawCodeMetrics(file, text=""): """ Private function to calculate the raw code metrics of one file. - + @param file source filename @type str @param text source text @@ -46,7 +46,7 @@ def batchRawCodeMetrics(argumentsList, send, fx, cancelled, maxProcesses=0): """ Module function to calculate the raw code metrics for a batch of files. - + @param argumentsList list of arguments tuples as given for rawCodeMetrics @type list @param send reference to send function @@ -80,9 +80,8 @@ # Start worker processes workers = [ - multiprocessing.Process( - target=workerTask, args=(taskQueue, doneQueue) - ) for _ in range(NumberOfProcesses) + multiprocessing.Process(target=workerTask, args=(taskQueue, doneQueue)) + for _ in range(NumberOfProcesses) ] for worker in workers: worker.start() @@ -92,7 +91,7 @@ for i in range(len(argumentsList)): resultSent = False wasCancelled = False - + while not resultSent: try: # get result (waiting max. 3 seconds and send it to frontend @@ -104,18 +103,18 @@ if cancelled(): wasCancelled = True break - + if wasCancelled or cancelled(): # just exit the loop ignoring the results of queued tasks break - + if i < endIndex: taskQueue.put(argumentsList[i + initialTasks]) # Tell child processes to stop for _ in range(NumberOfProcesses): - taskQueue.put('STOP') - + taskQueue.put("STOP") + for worker in workers: worker.join() worker.close() @@ -125,13 +124,13 @@ """ Module function acting as the parallel worker for the raw code metrics calculation. - + @param inputQueue input queue @type multiprocessing.Queue @param outputQueue output queue @type multiprocessing.Queue """ - for filename, source in iter(inputQueue.get, 'STOP'): + for filename, source in iter(inputQueue.get, "STOP"): result = __rawCodeMetrics(filename, source) outputQueue.put((filename, result)) @@ -139,7 +138,7 @@ def __rawCodeMetrics(file, text=""): """ Private function to calculate the raw code metrics for one Python file. - + @param file source filename @type str @param text source text @@ -148,18 +147,19 @@ @rtype (tuple of dict) """ from radon.raw import analyze + try: res = __raw2Dict(analyze(text)) except Exception as err: res = {"error": str(err)} - return (res, ) + return (res,) def __raw2Dict(obj): """ Private function to convert an object holding raw analysis results into a dictionary. - + @param obj object as returned from analyze() @type radon.raw.Module @return conversion result