Fixed an issue in the batch checker cancel function leading to the function not working if the background jobs had finished already.

Thu, 23 Apr 2015 20:05:38 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 23 Apr 2015 20:05:38 +0200
changeset 4235
81278aff6af9
parent 4234
40741c858639
child 4236
8d4e498a7af8

Fixed an issue in the batch checker cancel function leading to the function not working if the background jobs had finished already.

APIs/Python3/eric6.api file | annotate | diff | comparison | revisions
Documentation/Help/source.qch file | annotate | diff | comparison | revisions
Documentation/Source/eric6.Utilities.BackgroundService.html file | annotate | diff | comparison | revisions
Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleCheckerDialog.py file | annotate | diff | comparison | revisions
Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheckService.py file | annotate | diff | comparison | revisions
Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheckerDialog.py file | annotate | diff | comparison | revisions
Plugins/PluginCodeStyleChecker.py file | annotate | diff | comparison | revisions
Utilities/BackgroundService.py file | annotate | diff | comparison | revisions
--- a/APIs/Python3/eric6.api	Thu Apr 23 19:09:34 2015 +0200
+++ b/APIs/Python3/eric6.api	Thu Apr 23 20:05:38 2015 +0200
@@ -8459,7 +8459,7 @@
 eric6.Utilities.BackgroundService.BackgroundService.on_disconnectSocket?4(lang)
 eric6.Utilities.BackgroundService.BackgroundService.on_newConnection?4()
 eric6.Utilities.BackgroundService.BackgroundService.preferencesOrProjectChanged?4()
-eric6.Utilities.BackgroundService.BackgroundService.requestCancel?4(lang)
+eric6.Utilities.BackgroundService.BackgroundService.requestCancel?4(fx, lang)
 eric6.Utilities.BackgroundService.BackgroundService.restartService?4(language, forceKill=False)
 eric6.Utilities.BackgroundService.BackgroundService.serviceConnect?4(fx, lang, modulepath, module, callback, onErrorCallback=None, onBatchDone=None)
 eric6.Utilities.BackgroundService.BackgroundService.serviceDisconnect?4(fx, lang)
Binary file Documentation/Help/source.qch has changed
--- a/Documentation/Source/eric6.Utilities.BackgroundService.html	Thu Apr 23 19:09:34 2015 +0200
+++ b/Documentation/Source/eric6.Utilities.BackgroundService.html	Thu Apr 23 20:05:38 2015 +0200
@@ -207,7 +207,7 @@
         Public slot to restart the built in languages.
 </p><a NAME="BackgroundService.requestCancel" ID="BackgroundService.requestCancel"></a>
 <h4>BackgroundService.requestCancel</h4>
-<b>requestCancel</b>(<i>lang</i>)
+<b>requestCancel</b>(<i>fx, lang</i>)
 <p>
         Public method to ask a batch job to terminate.
 </p><dl>
--- a/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleCheckerDialog.py	Thu Apr 23 19:09:34 2015 +0200
+++ b/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleCheckerDialog.py	Thu Apr 23 20:05:38 2015 +0200
@@ -12,7 +12,7 @@
 import os
 import fnmatch
 
-from PyQt5.QtCore import pyqtSlot, Qt
+from PyQt5.QtCore import pyqtSlot, Qt, QTimer
 from PyQt5.QtGui import QIcon
 from PyQt5.QtWidgets import QDialog, QTreeWidgetItem, QAbstractButton, \
     QDialogButtonBox, QApplication, QHeaderView
@@ -570,27 +570,28 @@
         Private slot called when the code style check finished or the user
         pressed the cancel button.
         """
-        self.__finished = True
-        
-        self.cancelled = True
-        self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
-        self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
-        self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
-        self.statisticsButton.setEnabled(True)
-        self.showButton.setEnabled(True)
-        self.startButton.setEnabled(True)
-        
-        if self.noResults:
-            QTreeWidgetItem(self.resultList, [self.tr('No issues found.')])
-            QApplication.processEvents()
-            self.showButton.setEnabled(False)
-        else:
+        if not self.__finished:
+            self.__finished = True
+            
+            self.cancelled = True
+            self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
+            self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
+            self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
+            self.statisticsButton.setEnabled(True)
             self.showButton.setEnabled(True)
-        self.resultList.header().resizeSections(QHeaderView.ResizeToContents)
-        self.resultList.header().setStretchLastSection(True)
-        
-        self.checkProgress.setVisible(False)
-        self.checkProgressLabel.setVisible(False)
+            self.startButton.setEnabled(True)
+            
+            if self.noResults:
+                QTreeWidgetItem(self.resultList, [self.tr('No issues found.')])
+                QApplication.processEvents()
+                self.showButton.setEnabled(False)
+            else:
+                self.showButton.setEnabled(True)
+            self.resultList.header().resizeSections(QHeaderView.ResizeToContents)
+            self.resultList.header().setStretchLastSection(True)
+            
+            self.checkProgress.setVisible(False)
+            self.checkProgressLabel.setVisible(False)
     
     def __getEol(self, fn):
         """
@@ -852,6 +853,7 @@
         elif button == self.buttonBox.button(QDialogButtonBox.Cancel):
             if self.__batch:
                 self.styleCheckService.cancelStyleBatchCheck()
+                QTimer.singleShot(1000, self.__finish)
             else:
                 self.__finish()
         elif button == self.showButton:
--- a/Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheckService.py	Thu Apr 23 19:09:34 2015 +0200
+++ b/Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheckService.py	Thu Apr 23 20:05:38 2015 +0200
@@ -171,13 +171,10 @@
         """
         Public method to cancel all batch jobs.
         """
-        envs = []
         for lang in self.getLanguages():
             env = self.__supportedLanguages[lang][0]
-            if env not in envs:
-                envs.append(env)
-        for lang in envs:
-            self.backgroundService.requestCancel(lang)
+            self.backgroundService.requestCancel(
+                'batch_{0}Syntax'.format(lang), env)
     
     def __serviceError(self, fn, msg):
         """
--- a/Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheckerDialog.py	Thu Apr 23 19:09:34 2015 +0200
+++ b/Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheckerDialog.py	Thu Apr 23 20:05:38 2015 +0200
@@ -12,7 +12,7 @@
 import os
 import fnmatch
 
-from PyQt5.QtCore import pyqtSlot, Qt
+from PyQt5.QtCore import pyqtSlot, Qt, QTimer
 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QTreeWidgetItem, \
     QApplication, QHeaderView
 
@@ -331,24 +331,25 @@
         Private slot called when the syntax check finished or the user
         pressed the button.
         """
-        self.__finished = True
-        
-        self.cancelled = True
-        self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
-        self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
-        self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
-        
-        if self.noResults:
-            QTreeWidgetItem(self.resultList, [self.tr('No issues found.')])
-            QApplication.processEvents()
-            self.showButton.setEnabled(False)
-        else:
-            self.showButton.setEnabled(True)
-        self.resultList.header().resizeSections(QHeaderView.ResizeToContents)
-        self.resultList.header().setStretchLastSection(True)
-        
-        self.checkProgress.setVisible(False)
-        self.checkProgressLabel.setVisible(False)
+        if not self.__finished:
+            self.__finished = True
+            
+            self.cancelled = True
+            self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
+            self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
+            self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
+            
+            if self.noResults:
+                QTreeWidgetItem(self.resultList, [self.tr('No issues found.')])
+                QApplication.processEvents()
+                self.showButton.setEnabled(False)
+            else:
+                self.showButton.setEnabled(True)
+            self.resultList.header().resizeSections(QHeaderView.ResizeToContents)
+            self.resultList.header().setStretchLastSection(True)
+            
+            self.checkProgress.setVisible(False)
+            self.checkProgressLabel.setVisible(False)
         
     def on_buttonBox_clicked(self, button):
         """
@@ -361,6 +362,7 @@
         elif button == self.buttonBox.button(QDialogButtonBox.Cancel):
             if self.__batch:
                 self.syntaxCheckService.cancelSyntaxBatchCheck()
+                QTimer.singleShot(1000, self.__finish)
             else:
                 self.__finish()
         elif button == self.showButton:
--- a/Plugins/PluginCodeStyleChecker.py	Thu Apr 23 19:09:34 2015 +0200
+++ b/Plugins/PluginCodeStyleChecker.py	Thu Apr 23 20:05:38 2015 +0200
@@ -208,7 +208,7 @@
         Public method to cancel all batch jobs.
         """
         for lang in ['Python2', 'Python3']:
-            self.backgroundService.requestCancel(lang)
+            self.backgroundService.requestCancel('batch_style', lang)
     
     def __translateStyleCheck(self, fn, codeStyleCheckerStats, results):
         """
--- 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