eric6/Utilities/BackgroundService.py

Sun, 28 Mar 2021 15:00:11 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 28 Mar 2021 15:00:11 +0200
branch
maintenance
changeset 8176
31965986ecd1
parent 8043
0acf98cd089a
parent 8173
b2f9cda5cc0e
child 8273
698ae46f40a4
permissions
-rw-r--r--

Merged with default branch to prepare a new release.

3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7900
diff changeset
3 # Copyright (c) 2013 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
4 #
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
5
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
6 """
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
7 Module implementing a background service for the various checkers and other
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
8 Python interpreter dependent functions.
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
9 """
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
10
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
11 import json
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
12 import os
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
13 import struct
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
14 import sys
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
15 from zlib import adler32
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
16
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3591
diff changeset
17 from PyQt5.QtCore import QProcess, pyqtSignal, QTimer
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3591
diff changeset
18 from PyQt5.QtWidgets import QApplication
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3591
diff changeset
19 from PyQt5.QtNetwork import QTcpServer, QHostAddress
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
20
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
21 from E5Gui import E5MessageBox
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
22 from E5Gui.E5Application import e5App
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
23 import Preferences
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
24 import Utilities
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
25
3670
f0cb7579c0b4 Finished renaming eric5 for PyQt5 to eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3656
diff changeset
26 from eric6config import getConfig
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
27
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
28
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
29 class BackgroundService(QTcpServer):
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
30 """
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
31 Class implementing the main part of the background service.
5726
e1dbd217214a Fixed a few source docu issues (forgotten signals and exceptions).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5688
diff changeset
32
e1dbd217214a Fixed a few source docu issues (forgotten signals and exceptions).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5688
diff changeset
33 @signal serviceNotAvailable(function, language, filename, message)
e1dbd217214a Fixed a few source docu issues (forgotten signals and exceptions).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5688
diff changeset
34 emitted to indicate the non-availability of a service function
e1dbd217214a Fixed a few source docu issues (forgotten signals and exceptions).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5688
diff changeset
35 (str, str, str, str)
e1dbd217214a Fixed a few source docu issues (forgotten signals and exceptions).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5688
diff changeset
36 @signal batchJobDone(function, language) emitted to indicate the end of
e1dbd217214a Fixed a few source docu issues (forgotten signals and exceptions).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5688
diff changeset
37 a batch job (str, str)
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
38 """
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
39 serviceNotAvailable = pyqtSignal(str, str, str, str)
4218
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
40 batchJobDone = pyqtSignal(str, str)
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
41
8173
b2f9cda5cc0e Change code to give BackgroundService a 'parent'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
42 def __init__(self, parent=None):
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
43 """
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
44 Constructor
8173
b2f9cda5cc0e Change code to give BackgroundService a 'parent'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
45
b2f9cda5cc0e Change code to give BackgroundService a 'parent'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
46 @param parent reference to the parent object
b2f9cda5cc0e Change code to give BackgroundService a 'parent'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
47 @type QObject
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
48 """
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
49 self.processes = {}
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
50 self.connections = {}
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3173
diff changeset
51 self.isWorking = None
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
52 self.runningJob = [None, None, None, None]
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
53 self.__queue = []
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
54 self.services = {}
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
55
8173
b2f9cda5cc0e Change code to give BackgroundService a 'parent'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
56 super(BackgroundService, self).__init__(parent)
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
57
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
58 networkInterface = Preferences.getDebugger("NetworkInterface")
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
59 if networkInterface == "all" or '.' in networkInterface:
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
60 self.hostAddress = '127.0.0.1'
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
61 else:
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
62 self.hostAddress = '::1'
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
63 self.listen(QHostAddress(self.hostAddress))
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
64
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
65 self.newConnection.connect(self.on_newConnection)
3417
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
66
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
67 port = self.serverPort()
3538
33a75660df08 Change a comment in the background service to avoid a clash with a NOTE task marker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3505
diff changeset
68 ## Note: Need the port if started external in debugger:
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
69 print('Background Service listening on: {0:d}'.format(port))
5616
adcffadf4962 Reworked some __IGNORE_WARNING__ comments to be more specific.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
70 # __IGNORE_WARNING__
7635
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7630
diff changeset
71 venvName = Preferences.getDebugger("Python3VirtualEnv")
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7630
diff changeset
72 interpreter = e5App().getObject(
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7630
diff changeset
73 "VirtualEnvManager").getVirtualenvInterpreter(venvName)
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7630
diff changeset
74 if not interpreter:
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7630
diff changeset
75 interpreter = sys.executable.replace("w.exe", ".exe")
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7630
diff changeset
76 if interpreter:
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7630
diff changeset
77 process = self.__startExternalClient(interpreter, port)
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7630
diff changeset
78 if process:
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7630
diff changeset
79 self.processes['Python3'] = process, interpreter
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
80
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
81 def __startExternalClient(self, interpreter, port):
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
82 """
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
83 Private method to start the background client as external process.
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
84
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
85 @param interpreter path and name of the executable to start
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
86 @type str
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
87 @param port socket port to which the interpreter should connect
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
88 @type int
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
89 @return the process object
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
90 @rtype QProcess or None
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
91 """
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
92 if interpreter == "" or not Utilities.isinpath(interpreter):
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
93 return None
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
94
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
95 backgroundClient = os.path.join(
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
96 getConfig('ericDir'),
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
97 "Utilities", "BackgroundClient.py")
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
98 proc = QProcess()
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7965
diff changeset
99 proc.setProcessChannelMode(
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7965
diff changeset
100 QProcess.ProcessChannelMode.ForwardedChannels)
5762
76ef5f340007 Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5741
diff changeset
101 args = [backgroundClient, self.hostAddress, str(port),
76ef5f340007 Added functionality to limit the number of processes used for bachground services.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5741
diff changeset
102 str(Preferences.getUI("BackgroundServiceProcesses"))]
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
103 proc.start(interpreter, args)
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
104 if not proc.waitForStarted(10000):
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
105 proc = None
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
106 return proc
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
107
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
108 def __processQueue(self):
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
109 """
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
110 Private method to take the next service request and send it to the
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
111 client.
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
112 """
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3173
diff changeset
113 if self.__queue and self.isWorking is None:
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
114 fx, lang, fn, data = self.__queue.pop(0)
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
115 self.isWorking = lang
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
116 self.runningJob = fx, lang, fn, data
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
117 self.__send(fx, lang, fn, data)
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
118
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
119 def __send(self, fx, lang, fn, data):
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
120 """
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
121 Private method to send a job request to one of the clients.
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
122
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
123 @param fx remote function name to execute
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
124 @type str
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
125 @param lang language to connect to
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
126 @type str
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
127 @param fn filename for identification
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
128 @type str
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
129 @param data function argument(s)
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
130 @type any basic datatype
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
131 """
4235
81278aff6af9 Fixed an issue in the batch checker cancel function leading to the function not working if the background jobs had finished already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4221
diff changeset
132 self.__cancelled = False
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
133 connection = self.connections.get(lang)
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
134 if connection is None:
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
135 if fx != 'INIT':
7335
07ed3d73bf58 Syntax Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7259
diff changeset
136 # Avoid growing recursion depth which could itself result in an
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
137 # exception
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
138 QTimer.singleShot(
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
139 0,
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
140 lambda: self.serviceNotAvailable.emit(
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
141 fx, lang, fn, self.tr(
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
142 '{0} not configured.').format(lang)))
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
143 # Reset flag and continue processing queue
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3173
diff changeset
144 self.isWorking = None
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
145 self.__processQueue()
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
146 else:
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
147 packedData = json.dumps([fx, fn, data])
7192
a22eee00b052 Started removing runtime support for Python2 and PyQt4.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
148 packedData = bytes(packedData, 'utf-8')
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
149 header = struct.pack(
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
150 b'!II', len(packedData), adler32(packedData) & 0xffffffff)
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
151 connection.write(header)
4221
c9fdc07753a7 Implemented the Cancel logic for batch checks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4218
diff changeset
152 connection.write(b'JOB ') # 6 character message type
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
153 connection.write(packedData)
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
154
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
155 def __receive(self, lang):
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
156 """
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
157 Private method to receive the response from the clients.
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
158
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
159 @param lang language of the incoming connection
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
160 @type str
7628
f904d0eef264 Checked the reported security related issue reports generated by the new security checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
161 @exception RuntimeError raised if hashes don't match
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
162 """
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
163 connection = self.connections[lang]
4218
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
164 while connection.bytesAvailable():
4235
81278aff6af9 Fixed an issue in the batch checker cancel function leading to the function not working if the background jobs had finished already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4221
diff changeset
165 if self.__cancelled:
81278aff6af9 Fixed an issue in the batch checker cancel function leading to the function not working if the background jobs had finished already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4221
diff changeset
166 connection.readAll()
81278aff6af9 Fixed an issue in the batch checker cancel function leading to the function not working if the background jobs had finished already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4221
diff changeset
167 continue
81278aff6af9 Fixed an issue in the batch checker cancel function leading to the function not working if the background jobs had finished already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4221
diff changeset
168
4221
c9fdc07753a7 Implemented the Cancel logic for batch checks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4218
diff changeset
169 header = connection.read(struct.calcsize(b'!II'))
4218
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
170 length, datahash = struct.unpack(b'!II', header)
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
171
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
172 packedData = b''
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
173 while len(packedData) < length:
5875
3052fb9cf357 Some more speed adjustments for the background service.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5874
diff changeset
174 maxSize = length - len(packedData)
3052fb9cf357 Some more speed adjustments for the background service.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5874
diff changeset
175 if connection.bytesAvailable() < maxSize:
3052fb9cf357 Some more speed adjustments for the background service.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5874
diff changeset
176 connection.waitForReadyRead(50)
3052fb9cf357 Some more speed adjustments for the background service.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5874
diff changeset
177 packedData += connection.read(maxSize)
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
178
7628
f904d0eef264 Checked the reported security related issue reports generated by the new security checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
179 if adler32(packedData) & 0xffffffff != datahash:
f904d0eef264 Checked the reported security related issue reports generated by the new security checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
180 raise RuntimeError('Hashes not equal')
7192
a22eee00b052 Started removing runtime support for Python2 and PyQt4.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
181 packedData = packedData.decode('utf-8')
4218
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
182 # "check" if is's a tuple of 3 values
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
183 fx, fn, data = json.loads(packedData)
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
184
4218
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
185 if fx == 'INIT':
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
186 pass
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
187 elif fx == 'EXCEPTION':
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
188 # Remove connection because it'll close anyway
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
189 self.connections.pop(lang, None)
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
190 # Call sys.excepthook(type, value, traceback) to emulate the
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
191 # exception which was caught on the client
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
192 sys.excepthook(*data)
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
193 res = E5MessageBox.question(
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
194 None,
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
195 self.tr("Restart background client?"),
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
196 self.tr(
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
197 "<p>The background client for <b>{0}</b> has stopped"
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
198 " due to an exception. It's used by various plug-ins"
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
199 " like the different checkers.</p>"
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
200 "<p>Select"
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
201 "<ul>"
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
202 "<li><b>'Yes'</b> to restart the client, but abort the"
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
203 " last job</li>"
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
204 "<li><b>'Retry'</b> to restart the client and the last"
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
205 " job</li>"
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
206 "<li><b>'No'</b> to leave the client off.</li>"
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
207 "</ul></p>"
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
208 "<p>Note: The client can be restarted by opening and"
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
209 " accepting the preferences dialog or reloading/"
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
210 "changing the project.</p>").format(lang),
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
211 E5MessageBox.Yes | E5MessageBox.No | E5MessageBox.Retry,
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
212 E5MessageBox.Yes)
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
213
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
214 if res == E5MessageBox.Retry:
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
215 self.enqueueRequest(*self.runningJob)
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
216 else:
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
217 fx, lng, fn, data = self.runningJob
5741
ece3c72a24c3 Added some error handling to the Background service in case some errors are reported for an already deleted service.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
218 try:
ece3c72a24c3 Added some error handling to the Background service in case some errors are reported for an already deleted service.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
219 self.services[(fx, lng)][3](fx, lng, fn, self.tr(
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
220 "An error in Eric's background client stopped the"
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
221 " service.")
5741
ece3c72a24c3 Added some error handling to the Background service in case some errors are reported for an already deleted service.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
222 )
5901
96bb9e46ec89 Drop error message if no error handler is specified by plugin.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5875
diff changeset
223 except (KeyError, TypeError):
5741
ece3c72a24c3 Added some error handling to the Background service in case some errors are reported for an already deleted service.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
224 # ignore silently
ece3c72a24c3 Added some error handling to the Background service in case some errors are reported for an already deleted service.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
225 pass
4218
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
226 if res != E5MessageBox.No:
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
227 self.isWorking = None
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
228 self.restartService(lang, True)
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
229 return
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
230 elif data == 'Unknown service.':
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
231 callback = self.services.get((fx, lang))
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
232 if callback:
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
233 callback[3](fx, lang, fn, data)
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
234 elif fx.startswith("batch_"):
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
235 fx = fx.replace("batch_", "")
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
236 if data != "__DONE__":
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
237 callback = self.services.get((fx, lang))
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
238 if callback:
5688
76fc12e08e8f Introduced some code to improve defensive programming in the BackgroundService class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5616
diff changeset
239 if isinstance(data, (list, tuple)):
76fc12e08e8f Introduced some code to improve defensive programming in the BackgroundService class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5616
diff changeset
240 callback[2](fn, *data)
76fc12e08e8f Introduced some code to improve defensive programming in the BackgroundService class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5616
diff changeset
241 elif isinstance(data, str):
76fc12e08e8f Introduced some code to improve defensive programming in the BackgroundService class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5616
diff changeset
242 callback[3](fx, lang, fn, data)
4218
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
243 continue
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
244 else:
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
245 self.batchJobDone.emit(fx, lang)
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
246 else:
4218
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
247 callback = self.services.get((fx, lang))
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
248 if callback:
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
249 callback[2](fn, *data)
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
250
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3173
diff changeset
251 self.isWorking = None
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
252 self.__processQueue()
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
253
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
254 def preferencesOrProjectChanged(self):
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
255 """
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
256 Public slot to restart the built in languages.
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
257 """
7635
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7630
diff changeset
258 venvName = Preferences.getDebugger("Python3VirtualEnv")
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7630
diff changeset
259 interpreter = e5App().getObject(
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7630
diff changeset
260 "VirtualEnvManager").getVirtualenvInterpreter(venvName)
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7630
diff changeset
261 if not interpreter:
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7630
diff changeset
262 interpreter = sys.executable.replace("w.exe", ".exe")
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7630
diff changeset
263
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7630
diff changeset
264 # Tweak the processes list to reflect the changed interpreter
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7630
diff changeset
265 proc, inter = self.processes.pop('Python3', [None, None])
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7630
diff changeset
266 self.processes['Python3'] = proc, interpreter
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7630
diff changeset
267
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7630
diff changeset
268 self.restartService('Python3')
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
269
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
270 def restartService(self, language, forceKill=False):
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
271 """
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
272 Public method to restart a given language.
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
273
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
274 @param language to restart
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
275 @type str
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
276 @param forceKill flag to kill a running task
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
277 @type bool
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
278 """
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
279 try:
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
280 proc, interpreter = self.processes.pop(language)
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
281 except KeyError:
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
282 return
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
283
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
284 # Don't kill a process if it's still working
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
285 if not forceKill:
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
286 while self.isWorking is not None:
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
287 QApplication.processEvents()
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
288
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
289 conn = self.connections.pop(language, None)
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
290 if conn:
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
291 conn.blockSignals(True)
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
292 conn.close()
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
293 if proc:
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
294 proc.close()
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
295
6367
7bc6fc02d981 Fixed a few bugs caused by using the new virtual environment manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6348
diff changeset
296 if interpreter:
7bc6fc02d981 Fixed a few bugs caused by using the new virtual environment manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6348
diff changeset
297 port = self.serverPort()
7bc6fc02d981 Fixed a few bugs caused by using the new virtual environment manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6348
diff changeset
298 process = self.__startExternalClient(interpreter, port)
7bc6fc02d981 Fixed a few bugs caused by using the new virtual environment manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6348
diff changeset
299 if process:
7bc6fc02d981 Fixed a few bugs caused by using the new virtual environment manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6348
diff changeset
300 self.processes[language] = process, interpreter
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
301
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
302 def enqueueRequest(self, fx, lang, fn, data):
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
303 """
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
304 Public method implementing a queued processing of incoming events.
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
305
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
306 Duplicate service requests update an older request to avoid overrun or
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
307 starving of the services.
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
308
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
309 @param fx function name of the service
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
310 @type str
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
311 @param lang language to connect to
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
312 @type str
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
313 @param fn filename for identification
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
314 @type str
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
315 @param data function argument(s)
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
316 @type any basic datatype
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
317 """
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
318 args = [fx, lang, fn, data]
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
319 if fx == 'INIT':
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
320 self.__queue.insert(0, args)
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
321 else:
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
322 for pendingArg in self.__queue:
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
323 # Check if it's the same service request (fx, lang, fn equal)
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
324 if pendingArg[:3] == args[:3]:
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
325 # Update the data
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
326 pendingArg[3] = args[3]
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
327 break
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
328 else:
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
329 self.__queue.append(args)
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
330 self.__processQueue()
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
331
4235
81278aff6af9 Fixed an issue in the batch checker cancel function leading to the function not working if the background jobs had finished already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4221
diff changeset
332 def requestCancel(self, fx, lang):
4221
c9fdc07753a7 Implemented the Cancel logic for batch checks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4218
diff changeset
333 """
c9fdc07753a7 Implemented the Cancel logic for batch checks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4218
diff changeset
334 Public method to ask a batch job to terminate.
c9fdc07753a7 Implemented the Cancel logic for batch checks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4218
diff changeset
335
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
336 @param fx function name of the service
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
337 @type str
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
338 @param lang language to connect to
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
339 @type str
4221
c9fdc07753a7 Implemented the Cancel logic for batch checks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4218
diff changeset
340 """
4235
81278aff6af9 Fixed an issue in the batch checker cancel function leading to the function not working if the background jobs had finished already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4221
diff changeset
341 self.__cancelled = True
81278aff6af9 Fixed an issue in the batch checker cancel function leading to the function not working if the background jobs had finished already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4221
diff changeset
342
81278aff6af9 Fixed an issue in the batch checker cancel function leading to the function not working if the background jobs had finished already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4221
diff changeset
343 entriesToRemove = []
81278aff6af9 Fixed an issue in the batch checker cancel function leading to the function not working if the background jobs had finished already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4221
diff changeset
344 for pendingArg in self.__queue:
81278aff6af9 Fixed an issue in the batch checker cancel function leading to the function not working if the background jobs had finished already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4221
diff changeset
345 if pendingArg[:2] == [fx, lang]:
81278aff6af9 Fixed an issue in the batch checker cancel function leading to the function not working if the background jobs had finished already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4221
diff changeset
346 entriesToRemove.append(pendingArg)
81278aff6af9 Fixed an issue in the batch checker cancel function leading to the function not working if the background jobs had finished already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4221
diff changeset
347 for entryToRemove in entriesToRemove:
81278aff6af9 Fixed an issue in the batch checker cancel function leading to the function not working if the background jobs had finished already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4221
diff changeset
348 self.__queue.remove(entryToRemove)
81278aff6af9 Fixed an issue in the batch checker cancel function leading to the function not working if the background jobs had finished already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4221
diff changeset
349
4221
c9fdc07753a7 Implemented the Cancel logic for batch checks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4218
diff changeset
350 connection = self.connections.get(lang)
c9fdc07753a7 Implemented the Cancel logic for batch checks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4218
diff changeset
351 if connection is None:
c9fdc07753a7 Implemented the Cancel logic for batch checks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4218
diff changeset
352 return
c9fdc07753a7 Implemented the Cancel logic for batch checks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4218
diff changeset
353 else:
c9fdc07753a7 Implemented the Cancel logic for batch checks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4218
diff changeset
354 header = struct.pack(b'!II', 0, 0)
c9fdc07753a7 Implemented the Cancel logic for batch checks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4218
diff changeset
355 connection.write(header)
c9fdc07753a7 Implemented the Cancel logic for batch checks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4218
diff changeset
356 connection.write(b'CANCEL') # 6 character message type
c9fdc07753a7 Implemented the Cancel logic for batch checks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4218
diff changeset
357
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
358 def serviceConnect(
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
359 self, fx, lang, modulepath, module, callback,
4218
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
360 onErrorCallback=None, onBatchDone=None):
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
361 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3581
diff changeset
362 Public method to announce a new service to the background
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3581
diff changeset
363 service/client.
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
364
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
365 @param fx function name of the service
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
366 @type str
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
367 @param lang language of the new service
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
368 @type str
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
369 @param modulepath full path to the module
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
370 @type str
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
371 @param module name to import
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
372 @type str
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
373 @param callback function called on service response
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
374 @type function
4218
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
375 @param onErrorCallback function called, if client isn't available
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
376 (function)
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
377 @param onBatchDone function called when a batch job is done
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
378 @type function
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
379 """
7259
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
380 self.services[(fx, lang)] = (
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
381 modulepath, module, callback, onErrorCallback
7259
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
382 )
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
383 self.enqueueRequest('INIT', lang, fx, [modulepath, module])
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
384 if onErrorCallback:
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
385 self.serviceNotAvailable.connect(onErrorCallback)
4218
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
386 if onBatchDone:
f542ad1f76c5 Added a batch mode to the code style checker to make use of multiple CPUs/CPU-Cores.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
387 self.batchJobDone.connect(onBatchDone)
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
388
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
389 def serviceDisconnect(self, fx, lang):
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
390 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3581
diff changeset
391 Public method to remove the service from the service list.
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
392
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
393 @param fx function name of the service
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
394 @type function
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
395 @param lang language of the service
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
396 @type str
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
397 """
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
398 serviceArgs = self.services.pop((fx, lang), None)
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
399 if serviceArgs and serviceArgs[3]:
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
400 self.serviceNotAvailable.disconnect(serviceArgs[3])
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
401
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
402 def on_newConnection(self):
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
403 """
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
404 Private slot for new incoming connections from the clients.
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
405 """
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
406 connection = self.nextPendingConnection()
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
407 if not connection.waitForReadyRead(1000):
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
408 return
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
409 lang = connection.read(64)
7192
a22eee00b052 Started removing runtime support for Python2 and PyQt4.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
410 lang = lang.decode('utf-8')
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3173
diff changeset
411 # Avoid hanging of eric on shutdown
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
412 if self.connections.get(lang):
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
413 self.connections[lang].close()
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
414 if self.isWorking == lang:
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3173
diff changeset
415 self.isWorking = None
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
416 self.connections[lang] = connection
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
417 connection.readyRead.connect(
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
418 lambda x=lang: self.__receive(x))
3417
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
419 connection.disconnected.connect(
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
420 lambda x=lang: self.on_disconnectSocket(x))
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
421
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
422 for (fx, lng), args in self.services.items():
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
423 if lng == lang:
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
424 # Register service with modulepath and module
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
425 self.enqueueRequest('INIT', lng, fx, args[:2])
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
426
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
427 # Syntax check the open editors again
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
428 try:
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
429 vm = e5App().getObject("ViewManager")
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
430 except KeyError:
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
431 return
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
432 for editor in vm.getOpenEditors():
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
433 if editor.getLanguage() == lang:
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
434 QTimer.singleShot(0, editor.checkSyntax)
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
435
3417
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
436 def on_disconnectSocket(self, lang):
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
437 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3581
diff changeset
438 Private slot called when connection to a client is lost.
3417
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
439
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
440 @param lang client language which connection is lost
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
441 @type str
3417
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
442 """
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
443 conn = self.connections.pop(lang, None)
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
444 if conn:
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
445 conn.close()
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
446 fx, lng, fn, data = self.runningJob
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
447 if fx != 'INIT' and lng == lang:
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
448 self.services[(fx, lng)][3](fx, lng, fn, self.tr(
6321
f85288918089 BackgroundService: Little change to close the service when shutting down.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
449 "Eric's background client disconnected because of an"
f85288918089 BackgroundService: Little change to close the service when shutting down.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
450 " unknown reason.")
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
451 )
3417
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
452 self.isWorking = None
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
453
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
454 res = E5MessageBox.yesNo(
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
455 None,
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
456 self.tr('Background client disconnected.'),
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
457 self.tr(
4997
6dfb9119c85b Fixed a typo.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
458 'The background client for <b>{0}</b> disconnected because'
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
459 ' of an unknown reason.<br>Should it be restarted?'
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
460 ).format(lang),
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
461 yesDefault=True)
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
462 if res:
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
463 self.restartService(lang)
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
464
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
465 def shutdown(self):
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
466 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3581
diff changeset
467 Public method to cleanup the connections and processes when eric is
6321
f85288918089 BackgroundService: Little change to close the service when shutting down.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
468 shutting down.
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
469 """
6321
f85288918089 BackgroundService: Little change to close the service when shutting down.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
470 self.close()
f85288918089 BackgroundService: Little change to close the service when shutting down.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
471
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
472 for connection in self.connections.values():
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
473 # Prevent calling of on_disconnectSocket
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
474 connection.blockSignals(True)
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
475 connection.close()
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3172
diff changeset
476
6188
5a6ae3be31e6 Fixed some loop related coding issues detected by the extended code style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
477 for process, _interpreter in self.processes.values():
3505
84e7cee47d10 Start the background client always as external process.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3484
diff changeset
478 process.close()
7630
4010cc7e9c0b BackgroundService: improved the shutdown method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7628
diff changeset
479 if not process.waitForFinished(10000):
4010cc7e9c0b BackgroundService: improved the shutdown method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7628
diff changeset
480 process.kill()
3505
84e7cee47d10 Start the background client always as external process.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3484
diff changeset
481 process = None

eric ide

mercurial