src/eric7/Utilities/BackgroundService.py

branch
eric7
changeset 10072
891e71c29be0
parent 9656
578236b57ed5
child 10080
f834e57a5b13
--- a/src/eric7/Utilities/BackgroundService.py	Fri May 26 10:15:51 2023 +0200
+++ b/src/eric7/Utilities/BackgroundService.py	Fri May 26 18:10:36 2023 +0200
@@ -189,12 +189,11 @@
         @type str
         @exception RuntimeError raised if hashes don't match
         """
+        data = ""
+        fx = ""
+
         connection = self.connections[lang]
         while connection.bytesAvailable():
-            if self.__cancelled:
-                connection.readAll()
-                continue
-
             header = connection.read(struct.calcsize(b"!II"))
             length, datahash = struct.unpack(b"!II", header)
 
@@ -266,32 +265,38 @@
                         )
                 if res != EricMessageBox.No:
                     self.isWorking = None
-                    self.restartService(lang, True)
+                    self.restartService(lang, forceKill=True)
                     return
             elif data == "Unknown service.":
                 callback = self.services.get((fx, lang))
                 if callback:
                     callback[3](fx, lang, fn, data)
             elif fx.startswith("batch_"):
-                fx = fx.replace("batch_", "")
+                mfx = fx.replace("batch_", "")
                 if data != "__DONE__":
-                    callback = self.services.get((fx, lang))
+                    callback = self.services.get((mfx, lang))
                     if callback:
                         if isinstance(data, (list, tuple)):
                             callback[2](fn, *data)
                         elif isinstance(data, str):
-                            callback[3](fx, lang, fn, data)
+                            callback[3](mfx, lang, fn, data)
                     if data == "Unknown batch service.":
-                        self.batchJobDone.emit(fx, lang)
+                        self.batchJobDone.emit(mfx, lang)
                         self.__cancelled = True
                 else:
-                    self.batchJobDone.emit(fx, lang)
+                    self.batchJobDone.emit(mfx, lang)
                     self.restartService(lang, forceKill=True)
             else:
                 callback = self.services.get((fx, lang))
                 if callback:
                     callback[2](fn, *data)
 
+        if self.__cancelled and data != "__DONE__" and fx.startswith("batch_"):
+            # If it is a canceled batch job perform the batch done logic.
+            fx = fx.replace("batch_", "")
+            self.batchJobDone.emit(fx, lang)
+            self.restartService(lang, forceKill=True)
+
         self.isWorking = None
         self.__processQueue()
 
@@ -380,8 +385,6 @@
         @param lang language to connect to
         @type str
         """
-        self.__cancelled = True
-
         entriesToRemove = []
         for pendingArg in self.__queue:
             if pendingArg[:2] == [fx, lang]:
@@ -397,6 +400,8 @@
             connection.write(header)
             connection.write(b"CANCEL")  # 6 character message type
 
+        self.__cancelled = True
+
     def serviceConnect(
         self,
         fx,

eric ide

mercurial