src/eric7/Utilities/BackgroundService.py

Thu, 10 Apr 2025 18:39:29 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 10 Apr 2025 18:39:29 +0200
branch
eric7
changeset 11215
d07c71a34adf
parent 11148
15e30f0c76a8
permissions
-rw-r--r--

Changed the application shutdown code to use a signal to indicate the shutdown.

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
11090
f5f5f5803935 Updated copyright for 2025.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10697
diff changeset
3 # Copyright (c) 2013 - 2025 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
8943
23f9c7b9e18e Implemented some performance improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
11 import contextlib
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
12 import json
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
13 import os
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
14 import struct
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
15 import sys
10697
8a609e4c71b6 Made the various JSON based client-server interface a bit more resilient against slow data transfer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10692
diff changeset
16 import time
8a609e4c71b6 Made the various JSON based client-server interface a bit more resilient against slow data transfer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10692
diff changeset
17 import zlib
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
18
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
19 from PyQt6.QtCore import QProcess, QThread, QTimer, pyqtSignal
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
20 from PyQt6.QtNetwork import QHostAddress, QTcpServer
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
21 from PyQt6.QtWidgets import QApplication
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
22
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9521
diff changeset
23 from eric7 import Preferences
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9403
diff changeset
24 from eric7.EricWidgets import EricMessageBox
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9403
diff changeset
25 from eric7.EricWidgets.EricApplication import ericApp
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9521
diff changeset
26 from eric7.SystemUtilities import FileSystemUtilities, PythonUtilities
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
27
8309
10aa9235b817 Corrected a code style issue.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8307
diff changeset
28
3159
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.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
32
5726
e1dbd217214a Fixed a few source docu issues (forgotten signals and exceptions).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5691
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: 5691
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: 5691
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: 5691
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: 5691
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 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
39
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
40 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
41 batchJobDone = pyqtSignal(str, str)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
42
8173
b2f9cda5cc0e Change code to give BackgroundService a 'parent'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
43 def __init__(self, parent=None):
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
44 """
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
45 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
46
8173
b2f9cda5cc0e Change code to give BackgroundService a 'parent'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
47 @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
48 @type QObject
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
49 """
8478
b95aa969efdf BackgroundService: did some small changes that (hopefully) cure a nasty issue seen every now and than.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8456
diff changeset
50 super().__init__(parent)
b95aa969efdf BackgroundService: did some small changes that (hopefully) cure a nasty issue seen every now and than.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8456
diff changeset
51
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
52 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
53 self.connections = {}
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3173
diff changeset
54 self.isWorking = None
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
55 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
56 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
57 self.services = {}
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
58
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
59 networkInterface = Preferences.getDebugger("NetworkInterface")
9521
a663a8be64da Debugger
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
60 if networkInterface in ("allv4", "localv4") or "." in networkInterface:
a663a8be64da Debugger
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
61 # IPv4
a663a8be64da Debugger
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
62 self.__hostAddress = "127.0.0.1"
a663a8be64da Debugger
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
63 elif networkInterface in ("all", "allv6", "localv6"):
a663a8be64da Debugger
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
64 # IPv6
a663a8be64da Debugger
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
65 self.__hostAddress = "::1"
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
66 else:
9521
a663a8be64da Debugger
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
67 self.__hostAddress = networkInterface
a663a8be64da Debugger
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
68 self.listen(QHostAddress(self.__hostAddress))
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
69
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
70 self.newConnection.connect(self.on_newConnection)
11215
d07c71a34adf Changed the application shutdown code to use a signal to indicate the shutdown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 11148
diff changeset
71 parent.shutdown.connect(self.__shutdown)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
72
9521
a663a8be64da Debugger
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
73 ## Note: Need the address and port if started external in debugger:
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
74 port = self.serverPort()
9521
a663a8be64da Debugger
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
75 hostAddressStr = (
a663a8be64da Debugger
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
76 "[{0}]".format(self.__hostAddress)
a663a8be64da Debugger
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
77 if ":" in self.__hostAddress
a663a8be64da Debugger
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
78 else self.__hostAddress
a663a8be64da Debugger
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
79 )
a663a8be64da Debugger
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
80 print("Background Service listening on: {0}:{1:d}".format(hostAddressStr, port))
11148
15e30f0c76a8 Adjusted the code to the modified issue codes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 11090
diff changeset
81 # __IGNORE_WARNING_M-801__
9328
49a0a9cb2505 Fixed some code style issues detected by the new checks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9317
diff changeset
82
9317
bf8135417cd3 Refactored some code in BackgroundService.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
83 interpreter = self.__getPythonInterpreter()
bf8135417cd3 Refactored some code in BackgroundService.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
84 if interpreter:
bf8135417cd3 Refactored some code in BackgroundService.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
85 process = self.__startExternalClient(interpreter, port)
bf8135417cd3 Refactored some code in BackgroundService.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
86 if process:
bf8135417cd3 Refactored some code in BackgroundService.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
87 self.processes["Python3"] = process, interpreter
bf8135417cd3 Refactored some code in BackgroundService.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
88
bf8135417cd3 Refactored some code in BackgroundService.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
89 def __getPythonInterpreter(self):
bf8135417cd3 Refactored some code in BackgroundService.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
90 """
bf8135417cd3 Refactored some code in BackgroundService.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
91 Private method to generate the path of the Python interpreter to be
bf8135417cd3 Refactored some code in BackgroundService.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
92 used to run the background client.
9328
49a0a9cb2505 Fixed some code style issues detected by the new checks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9317
diff changeset
93
9317
bf8135417cd3 Refactored some code in BackgroundService.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
94 @return path of the Python interpreter
bf8135417cd3 Refactored some code in BackgroundService.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
95 @rtype str
bf8135417cd3 Refactored some code in BackgroundService.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
96 """
7635
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7630
diff changeset
97 venvName = Preferences.getDebugger("Python3VirtualEnv")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
98 interpreter = (
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
99 ericApp().getObject("VirtualEnvManager").getVirtualenvInterpreter(venvName)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
100 )
7635
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7630
diff changeset
101 if not interpreter:
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9521
diff changeset
102 interpreter = PythonUtilities.getPythonExecutable()
9317
bf8135417cd3 Refactored some code in BackgroundService.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
103 return interpreter
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
104
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
105 def __startExternalClient(self, interpreter, port):
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
106 """
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
107 Private method to start the background client as external process.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
108
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
109 @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
110 @type str
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
111 @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
112 @type int
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
113 @return the process object
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
114 @rtype QProcess or None
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
115 """
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9521
diff changeset
116 if interpreter == "" or not FileSystemUtilities.isinpath(interpreter):
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
117 return None
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
118
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
119 backgroundClient = os.path.join(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
120 os.path.dirname(__file__), "BackgroundClient.py"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
121 )
8456
00a7d3bd87dc Added an owner to the QProcess objects created by the BackgroundService.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8366
diff changeset
122 proc = QProcess(self)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
123 proc.setProcessChannelMode(QProcess.ProcessChannelMode.ForwardedChannels)
8307
01a323d3d4d7 Background Server, Client: pass the path to the Python library of the eric (virtual) environment to the client to enable service plug-ins to load dependencies from there.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8264
diff changeset
124 args = [
01a323d3d4d7 Background Server, Client: pass the path to the Python library of the eric (virtual) environment to the client to enable service plug-ins to load dependencies from there.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8264
diff changeset
125 backgroundClient,
9521
a663a8be64da Debugger
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
126 self.__hostAddress,
8307
01a323d3d4d7 Background Server, Client: pass the path to the Python library of the eric (virtual) environment to the client to enable service plug-ins to load dependencies from there.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8264
diff changeset
127 str(port),
01a323d3d4d7 Background Server, Client: pass the path to the Python library of the eric (virtual) environment to the client to enable service plug-ins to load dependencies from there.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8264
diff changeset
128 str(Preferences.getUI("BackgroundServiceProcesses")),
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9521
diff changeset
129 PythonUtilities.getPythonLibraryDirectory(),
8307
01a323d3d4d7 Background Server, Client: pass the path to the Python library of the eric (virtual) environment to the client to enable service plug-ins to load dependencies from there.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8264
diff changeset
130 ]
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
131 proc.start(interpreter, args)
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
132 if not proc.waitForStarted(10000):
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
133 proc = None
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
134 return proc
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
135
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
136 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
137 """
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
138 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
139 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
140 """
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3173
diff changeset
141 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
142 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
143 self.isWorking = lang
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
144 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
145 self.__send(fx, lang, fn, data)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
146
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
147 def __send(self, fx, lang, fn, data):
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
148 """
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
149 Private method to send a job request to one of the clients.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
150
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
151 @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
152 @type str
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
153 @param lang language to connect to
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
154 @type str
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
155 @param fn filename for identification
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
156 @type str
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
157 @param data function argument(s)
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
158 @type any basic datatype
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
159 """
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
160 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
161 connection = self.connections.get(lang)
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
162 if connection is None:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
163 if fx != "INIT":
7335
07ed3d73bf58 Syntax Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7259
diff changeset
164 # 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
165 # exception
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
166 QTimer.singleShot(
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
167 0,
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
168 lambda: self.serviceNotAvailable.emit(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
169 fx, lang, fn, self.tr("{0} not configured.").format(lang)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
170 ),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
171 )
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
172 # 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
173 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
174 self.__processQueue()
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
175 else:
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
176 packedData = json.dumps([fx, fn, data])
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
177 packedData = bytes(packedData, "utf-8")
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
178 header = struct.pack(
10697
8a609e4c71b6 Made the various JSON based client-server interface a bit more resilient against slow data transfer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10692
diff changeset
179 b"!II", len(packedData), zlib.adler32(packedData) & 0xFFFFFFFF
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
180 )
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
181 connection.write(header)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
182 connection.write(b"JOB ") # 6 character message type
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
183 connection.write(packedData)
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
184
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
185 def __receive(self, lang):
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
186 """
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
187 Private method to receive the response from the clients.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
188
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
189 @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
190 @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
191 @exception RuntimeError raised if hashes don't match
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
192 """
10697
8a609e4c71b6 Made the various JSON based client-server interface a bit more resilient against slow data transfer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10692
diff changeset
193 headerSize = struct.calcsize(b"!II")
8a609e4c71b6 Made the various JSON based client-server interface a bit more resilient against slow data transfer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10692
diff changeset
194
10072
891e71c29be0 BackgroundService
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9656
diff changeset
195 data = ""
891e71c29be0 BackgroundService
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9656
diff changeset
196 fx = ""
891e71c29be0 BackgroundService
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9656
diff changeset
197
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
198 connection = self.connections[lang]
10697
8a609e4c71b6 Made the various JSON based client-server interface a bit more resilient against slow data transfer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10692
diff changeset
199 while connection and connection.bytesAvailable():
8a609e4c71b6 Made the various JSON based client-server interface a bit more resilient against slow data transfer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10692
diff changeset
200 now = time.monotonic()
8a609e4c71b6 Made the various JSON based client-server interface a bit more resilient against slow data transfer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10692
diff changeset
201 while connection.bytesAvailable() < headerSize:
8a609e4c71b6 Made the various JSON based client-server interface a bit more resilient against slow data transfer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10692
diff changeset
202 connection.waitForReadyRead(50)
8a609e4c71b6 Made the various JSON based client-server interface a bit more resilient against slow data transfer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10692
diff changeset
203 if time.monotonic() - now > 2.0: # 2 seconds timeout
8a609e4c71b6 Made the various JSON based client-server interface a bit more resilient against slow data transfer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10692
diff changeset
204 return
8a609e4c71b6 Made the various JSON based client-server interface a bit more resilient against slow data transfer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10692
diff changeset
205 header = connection.read(headerSize)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
206 length, datahash = struct.unpack(b"!II", header)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
207
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
208 packedData = b""
10697
8a609e4c71b6 Made the various JSON based client-server interface a bit more resilient against slow data transfer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10692
diff changeset
209 now = time.monotonic()
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
210 while len(packedData) < length:
5875
3052fb9cf357 Some more speed adjustments for the background service.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5874
diff changeset
211 maxSize = length - len(packedData)
3052fb9cf357 Some more speed adjustments for the background service.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5874
diff changeset
212 if connection.bytesAvailable() < maxSize:
3052fb9cf357 Some more speed adjustments for the background service.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5874
diff changeset
213 connection.waitForReadyRead(50)
10697
8a609e4c71b6 Made the various JSON based client-server interface a bit more resilient against slow data transfer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10692
diff changeset
214 newData = connection.read(maxSize)
8a609e4c71b6 Made the various JSON based client-server interface a bit more resilient against slow data transfer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10692
diff changeset
215 if newData:
8a609e4c71b6 Made the various JSON based client-server interface a bit more resilient against slow data transfer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10692
diff changeset
216 packedData += newData
8a609e4c71b6 Made the various JSON based client-server interface a bit more resilient against slow data transfer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10692
diff changeset
217 else:
8a609e4c71b6 Made the various JSON based client-server interface a bit more resilient against slow data transfer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10692
diff changeset
218 if time.monotonic() - now > 2.0: # 2 seconds timeout
8a609e4c71b6 Made the various JSON based client-server interface a bit more resilient against slow data transfer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10692
diff changeset
219 break
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
220
10697
8a609e4c71b6 Made the various JSON based client-server interface a bit more resilient against slow data transfer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10692
diff changeset
221 if zlib.adler32(packedData) & 0xFFFFFFFF != datahash:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
222 raise RuntimeError("Hashes not equal")
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
223 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
224 # "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
225 fx, fn, data = json.loads(packedData)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
226
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
227 if fx == "INIT":
8264
f95dde35d0ab Background Service: added code to signal initialization errors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8243
diff changeset
228 if data != "ok":
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
229 EricMessageBox.critical(
8264
f95dde35d0ab Background Service: added code to signal initialization errors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8243
diff changeset
230 None,
f95dde35d0ab Background Service: added code to signal initialization errors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8243
diff changeset
231 self.tr("Initialization of Background Service"),
f95dde35d0ab Background Service: added code to signal initialization errors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8243
diff changeset
232 self.tr(
f95dde35d0ab Background Service: added code to signal initialization errors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8243
diff changeset
233 "<p>Initialization of Background Service"
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
234 " <b>{0}</b> failed.</p><p>Reason: {1}</p>"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
235 ).format(fn, data),
8264
f95dde35d0ab Background Service: added code to signal initialization errors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8243
diff changeset
236 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
237 elif fx == "EXCEPTION":
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
238 # 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
239 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
240 # 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
241 # 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
242 sys.excepthook(*data)
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
243 res = EricMessageBox.question(
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
244 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
245 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
246 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
247 "<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
248 " 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
249 " 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
250 "<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
251 "<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
252 "<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
253 " 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
254 "<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
255 " 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
256 "<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
257 "</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
258 "<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
259 " accepting the preferences dialog or reloading/"
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
260 "changing the project.</p>"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
261 ).format(lang),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
262 EricMessageBox.Yes | EricMessageBox.No | EricMessageBox.Retry,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
263 EricMessageBox.Yes,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
264 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
265
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
266 if res == EricMessageBox.Retry:
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
267 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
268 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
269 fx, lng, fn, data = self.runningJob
8243
cc717c2ae956 Applied some more code simplifications suggested by the new Simplify checker (Y105: use contextlib.suppress) (batch 2).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8218
diff changeset
270 with contextlib.suppress(KeyError, TypeError):
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
271 self.services[(fx, lng)][3](
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
272 fx,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
273 lng,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
274 fn,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
275 self.tr(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
276 "An error in Eric's background client stopped the"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
277 " service."
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
278 ),
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
279 )
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
280 if res != EricMessageBox.No:
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
281 self.isWorking = None
10072
891e71c29be0 BackgroundService
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9656
diff changeset
282 self.restartService(lang, forceKill=True)
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
283 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
284 elif data == "Unknown service.":
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
285 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
286 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
287 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
288 elif fx.startswith("batch_"):
10072
891e71c29be0 BackgroundService
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9656
diff changeset
289 mfx = fx.replace("batch_", "")
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
290 if data != "__DONE__":
10072
891e71c29be0 BackgroundService
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9656
diff changeset
291 callback = self.services.get((mfx, 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
292 if callback:
5691
372ac1c1c228 Introduced some code to improve defensive programming in the BackgroundService class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5616
diff changeset
293 if isinstance(data, (list, tuple)):
372ac1c1c228 Introduced some code to improve defensive programming in the BackgroundService class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5616
diff changeset
294 callback[2](fn, *data)
372ac1c1c228 Introduced some code to improve defensive programming in the BackgroundService class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5616
diff changeset
295 elif isinstance(data, str):
10072
891e71c29be0 BackgroundService
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9656
diff changeset
296 callback[3](mfx, lang, fn, data)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
297 if data == "Unknown batch service.":
10072
891e71c29be0 BackgroundService
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9656
diff changeset
298 self.batchJobDone.emit(mfx, lang)
8264
f95dde35d0ab Background Service: added code to signal initialization errors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8243
diff changeset
299 self.__cancelled = True
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
300 else:
10072
891e71c29be0 BackgroundService
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9656
diff changeset
301 self.batchJobDone.emit(mfx, lang)
9329
bd8e621c3c20 Restart the background client after each batch job to (hopefully) get rid of an observed performance issue.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9328
diff changeset
302 self.restartService(lang, forceKill=True)
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
303 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
304 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
305 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
306 callback[2](fn, *data)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
307
10072
891e71c29be0 BackgroundService
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9656
diff changeset
308 if self.__cancelled and data != "__DONE__" and fx.startswith("batch_"):
891e71c29be0 BackgroundService
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9656
diff changeset
309 # If it is a canceled batch job perform the batch done logic.
891e71c29be0 BackgroundService
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9656
diff changeset
310 fx = fx.replace("batch_", "")
891e71c29be0 BackgroundService
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9656
diff changeset
311 self.batchJobDone.emit(fx, lang)
891e71c29be0 BackgroundService
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9656
diff changeset
312 self.restartService(lang, forceKill=True)
891e71c29be0 BackgroundService
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9656
diff changeset
313
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3173
diff changeset
314 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
315 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
316
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
317 def preferencesOrProjectChanged(self):
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
318 """
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
319 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
320 """
9317
bf8135417cd3 Refactored some code in BackgroundService.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
321 interpreter = self.__getPythonInterpreter()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
322
7635
0cdead130a81 Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7630
diff changeset
323 # Tweak the processes list to reflect the changed interpreter
10692
9becf9ca115c Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10439
diff changeset
324 proc, _inter = self.processes.pop("Python3", [None, None])
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
325 self.processes["Python3"] = proc, interpreter
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
326
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
327 self.restartService("Python3")
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
328
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
329 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
330 """
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
331 Public method to restart a given language.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
332
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
333 @param language to restart
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
334 @type str
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
335 @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
336 @type bool
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
337 """
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
338 try:
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
339 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
340 except KeyError:
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
341 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
342
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
343 # 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
344 if not forceKill:
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
345 while self.isWorking is not None:
8943
23f9c7b9e18e Implemented some performance improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
346 QThread.msleep(100)
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
347 QApplication.processEvents()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
348
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
349 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
350 if conn:
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
351 conn.blockSignals(True)
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
352 conn.close()
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
353 if proc:
9656
578236b57ed5 Added code to ignore a runtime error when restarting a background service.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
354 with contextlib.suppress(RuntimeError):
578236b57ed5 Added code to ignore a runtime error when restarting a background service.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
355 proc.close()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
356
6367
7bc6fc02d981 Fixed a few bugs caused by using the new virtual environment manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6348
diff changeset
357 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
358 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
359 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
360 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
361 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
362
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
363 def enqueueRequest(self, fx, lang, fn, data):
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
364 """
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
365 Public method implementing a queued processing of incoming events.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
366
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
367 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
368 starving of the services.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
369
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
370 @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
371 @type str
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
372 @param lang language to connect to
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
373 @type str
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
374 @param fn filename for identification
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
375 @type str
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
376 @param data function argument(s)
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
377 @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
378 """
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
379 args = [fx, lang, fn, data]
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
380 if fx == "INIT":
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
381 self.__queue.insert(0, args)
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
382 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
383 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
384 # 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
385 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
386 # 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
387 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
388 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
389 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
390 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
391 self.__processQueue()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
392
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
393 def requestCancel(self, fx, lang):
4221
c9fdc07753a7 Implemented the Cancel logic for batch checks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4218
diff changeset
394 """
c9fdc07753a7 Implemented the Cancel logic for batch checks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4218
diff changeset
395 Public method to ask a batch job to terminate.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
396
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
397 @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
398 @type str
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
399 @param lang language to connect to
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
400 @type str
4221
c9fdc07753a7 Implemented the Cancel logic for batch checks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4218
diff changeset
401 """
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
402 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
403 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
404 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
405 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
406 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
407 self.__queue.remove(entryToRemove)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
408
4221
c9fdc07753a7 Implemented the Cancel logic for batch checks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4218
diff changeset
409 connection = self.connections.get(lang)
c9fdc07753a7 Implemented the Cancel logic for batch checks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4218
diff changeset
410 if connection is None:
c9fdc07753a7 Implemented the Cancel logic for batch checks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4218
diff changeset
411 return
c9fdc07753a7 Implemented the Cancel logic for batch checks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4218
diff changeset
412 else:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
413 header = struct.pack(b"!II", 0, 0)
4221
c9fdc07753a7 Implemented the Cancel logic for batch checks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4218
diff changeset
414 connection.write(header)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
415 connection.write(b"CANCEL") # 6 character message type
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
416
10072
891e71c29be0 BackgroundService
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9656
diff changeset
417 self.__cancelled = True
891e71c29be0 BackgroundService
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9656
diff changeset
418
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
419 def serviceConnect(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
420 self,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
421 fx,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
422 lang,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
423 modulepath,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
424 module,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
425 callback,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
426 onErrorCallback=None,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
427 onBatchDone=None,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
428 ):
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
429 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3581
diff changeset
430 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
431 service/client.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
432
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
433 @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
434 @type str
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
435 @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
436 @type str
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
437 @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
438 @type str
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
439 @param module name to import
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
440 @type str
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
441 @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
442 @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
443 @param onErrorCallback function called, if client isn't available
10433
328f3ec4b77a Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10080
diff changeset
444 @type function
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
445 @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
446 @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
447 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
448 self.services[(fx, lang)] = (modulepath, module, callback, onErrorCallback)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
449 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
450 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
451 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
452 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
453 self.batchJobDone.connect(onBatchDone)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
454
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
455 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
456 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3581
diff changeset
457 Public method to remove the service from the service list.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
458
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
459 @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
460 @type function
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
461 @param lang language of the service
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
462 @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
463 """
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
464 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
465 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
466 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
467
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
468 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
469 """
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
470 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
471 """
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
472 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
473 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
474 return
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
475 lang = connection.read(64)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
476 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
477 # 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
478 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
479 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
480 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
481 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
482 self.connections[lang] = connection
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
483 connection.readyRead.connect(lambda: self.__receive(lang))
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
484 connection.disconnected.connect(lambda: self.on_disconnectSocket(lang))
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
485
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
486 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
487 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
488 # Register service with modulepath and module
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
489 self.enqueueRequest("INIT", lng, fx, args[:2])
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
490
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
491 # 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
492 try:
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
493 vm = ericApp().getObject("ViewManager")
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
494 except KeyError:
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
495 return
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
496 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
497 if editor.getLanguage() == lang:
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
498 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
499
3417
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
500 def on_disconnectSocket(self, lang):
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
501 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3581
diff changeset
502 Private slot called when connection to a client is lost.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
503
7965
48fbf9149d16 BackgroundService and -Client: fixed a few typos.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
504 @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
505 @type str
3417
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
506 """
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
507 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
508 if conn:
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
509 conn.close()
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
510 fx, lng, fn, data = self.runningJob
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
511 if fx != "INIT" and lng == lang:
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
512 self.services[(fx, lng)][3](
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
513 fx,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
514 lng,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
515 fn,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
516 self.tr(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
517 "Eric's background client disconnected because of an"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
518 " unknown reason."
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
519 ),
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
520 )
3417
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
521 self.isWorking = None
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
522
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
523 res = EricMessageBox.yesNo(
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
524 None,
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
525 self.tr("Background client disconnected."),
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
526 self.tr(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
527 "The background client for <b>{0}</b> disconnected because"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
528 " of an unknown reason.<br>Should it be restarted?"
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
529 ).format(lang),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
530 yesDefault=True,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
531 )
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
532 if res:
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
533 self.restartService(lang)
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
534
11215
d07c71a34adf Changed the application shutdown code to use a signal to indicate the shutdown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 11148
diff changeset
535 def __shutdown(self):
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
536 """
11215
d07c71a34adf Changed the application shutdown code to use a signal to indicate the shutdown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 11148
diff changeset
537 Private 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
538 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
539 """
6321
f85288918089 BackgroundService: Little change to close the service when shutting down.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
540 self.close()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
541
3579
eccd12461319 BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3538
diff changeset
542 for connection in self.connections.values():
10080
f834e57a5b13 Fixed a few issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10072
diff changeset
543 with contextlib.suppress(RuntimeError):
f834e57a5b13 Fixed a few issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10072
diff changeset
544 connection.readyRead.disconnect()
f834e57a5b13 Fixed a few issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10072
diff changeset
545 connection.disconnected.disconnect()
f834e57a5b13 Fixed a few issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10072
diff changeset
546 connection.close()
f834e57a5b13 Fixed a few issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10072
diff changeset
547 connection.deleteLater()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
548
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
549 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
550 process.close()
7630
4010cc7e9c0b BackgroundService: improved the shutdown method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7628
diff changeset
551 if not process.waitForFinished(10000):
4010cc7e9c0b BackgroundService: improved the shutdown method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7628
diff changeset
552 process.kill()
3505
84e7cee47d10 Start the background client always as external process.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3484
diff changeset
553 process = None

eric ide

mercurial