Utilities/BackgroundService.py

changeset 4235
81278aff6af9
parent 4221
c9fdc07753a7
child 4236
8d4e498a7af8
diff -r 40741c858639 -r 81278aff6af9 Utilities/BackgroundService.py
--- a/Utilities/BackgroundService.py	Thu Apr 23 19:09:34 2015 +0200
+++ b/Utilities/BackgroundService.py	Thu Apr 23 20:05:38 2015 +0200
@@ -112,6 +112,7 @@
         @param fn filename for identification (str)
         @param data function argument(s) (any basic datatype)
         """
+        self.__cancelled = False
         connection = self.connections.get(lang)
         if connection is None:
             if fx != 'INIT':
@@ -143,6 +144,10 @@
         """
         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)
             
@@ -291,12 +296,21 @@
                 self.__queue.append(args)
         self.__processQueue()
     
-    def requestCancel(self, lang):
+    def requestCancel(self, fx, lang):
         """
         Public method to ask a batch job to terminate.
         
         @param lang language to connect to (str)
         """
+        self.__cancelled = True
+        
+        entriesToRemove = []
+        for pendingArg in self.__queue:
+            if pendingArg[:2] == [fx, lang]:
+                entriesToRemove.append(pendingArg)
+        for entryToRemove in entriesToRemove:
+            self.__queue.remove(entryToRemove)
+        
         connection = self.connections.get(lang)
         if connection is None:
             return

eric ide

mercurial