src/eric7/CodeFormatting/BlackFormattingDialog.py

branch
eric7
changeset 9289
ba49c41e8f63
parent 9284
3b3a4f659782
child 9292
a5c8a0213fe3
diff -r ce20d7c936b1 -r ba49c41e8f63 src/eric7/CodeFormatting/BlackFormattingDialog.py
--- a/src/eric7/CodeFormatting/BlackFormattingDialog.py	Tue Aug 16 13:14:42 2022 +0200
+++ b/src/eric7/CodeFormatting/BlackFormattingDialog.py	Tue Aug 16 19:07:16 2022 +0200
@@ -272,8 +272,11 @@
         taskQueue = multiprocessing.Queue()
         doneQueue = multiprocessing.Queue()
 
-        # Submit tasks
-        for file in files:
+        # Submit tasks (initially two times the number of processes)
+        tasks = len(files)
+        initialTasks = 2 * NumberOfProcesses
+        for _ in range(initialTasks):
+            file = files.pop(0)
             relSrc = self.__project.getRelativePath(str(file)) if self.__project else ""
             taskQueue.put((file, relSrc))
 
@@ -289,7 +292,7 @@
             worker.start()
 
         # Get the results from the worker tasks
-        for _ in range(len(files)):
+        for _ in range(tasks):
             result = doneQueue.get()
             self.__handleBlackFormattingResult(
                 result.status, result.filename, result.data
@@ -298,13 +301,16 @@
             if self.__cancelled:
                 break
 
-        if self.__cancelled:
-            for worker in workers:
-                worker.terminate()
-        else:
-            # Tell child processes to stop
-            for _ in range(NumberOfProcesses):
-                taskQueue.put("STOP")
+            if files:
+                file = files.pop(0)
+                relSrc = (
+                    self.__project.getRelativePath(str(file)) if self.__project else ""
+                )
+                taskQueue.put((file, relSrc))
+
+        # Tell child processes to stop
+        for _ in range(NumberOfProcesses):
+            taskQueue.put("STOP")
 
         for worker in workers:
             worker.join()

eric ide

mercurial