13 |
13 |
14 import json |
14 import json |
15 import os |
15 import os |
16 import struct |
16 import struct |
17 import sys |
17 import sys |
18 import threading |
|
19 from zlib import adler32 |
18 from zlib import adler32 |
20 |
19 |
21 from PyQt4.QtCore import QProcess, pyqtSignal |
20 from PyQt4.QtCore import QProcess, pyqtSignal |
22 from PyQt4.QtGui import QApplication |
21 from PyQt4.QtGui import QApplication |
23 from PyQt4.QtNetwork import QTcpServer, QHostAddress |
22 from PyQt4.QtNetwork import QTcpServer, QHostAddress |
24 |
23 |
25 import Preferences |
24 import Preferences |
26 import Utilities |
25 import Utilities |
27 from Utilities.BackgroundClient import BackgroundClient |
|
28 |
26 |
29 from eric5config import getConfig |
27 from eric5config import getConfig |
30 |
28 |
31 |
29 |
32 class BackgroundService(QTcpServer): |
30 class BackgroundService(QTcpServer): |
57 self.newConnection.connect(self.on_newConnection) |
55 self.newConnection.connect(self.on_newConnection) |
58 |
56 |
59 port = self.serverPort() |
57 port = self.serverPort() |
60 ## NOTE: Need the port if started external in debugger: |
58 ## NOTE: Need the port if started external in debugger: |
61 print('BackgroundService listening on: %i' % port) |
59 print('BackgroundService listening on: %i' % port) |
62 if sys.platform == 'win32': |
|
63 interpreterCompare = Utilities.samefilepath |
|
64 else: |
|
65 interpreterCompare = Utilities.samepath |
|
66 |
|
67 for pyName in ['Python', 'Python3']: |
60 for pyName in ['Python', 'Python3']: |
68 interpreter = Preferences.getDebugger( |
61 interpreter = Preferences.getDebugger( |
69 pyName + "Interpreter") |
62 pyName + "Interpreter") |
70 |
63 process = self.__startExternalClient(interpreter, port) |
71 if interpreterCompare(interpreter, sys.executable): |
|
72 process = self.__startInternalClient(port) |
|
73 else: |
|
74 process = self.__startExternalClient(interpreter, port) |
|
75 if process: |
64 if process: |
76 self.processes.append(process) |
65 self.processes.append(process) |
77 |
66 |
78 def __startExternalClient(self, interpreter, port): |
67 def __startExternalClient(self, interpreter, port): |
79 """ |
68 """ |
93 args = [backgroundClient, self.hostAddress, str(port)] |
82 args = [backgroundClient, self.hostAddress, str(port)] |
94 proc.start(interpreter, args) |
83 proc.start(interpreter, args) |
95 if not proc.waitForStarted(10000): |
84 if not proc.waitForStarted(10000): |
96 proc = None |
85 proc = None |
97 return proc |
86 return proc |
98 |
|
99 def __startInternalClient(self, port): |
|
100 """ |
|
101 Private method to start the background client as internal thread. |
|
102 |
|
103 @param port socket port to which the interpreter should connect (int) |
|
104 @return the thread object (Thread) or None |
|
105 """ |
|
106 backgroundClient = BackgroundClient( |
|
107 self.hostAddress, port) |
|
108 thread = threading.Thread(target=backgroundClient.run) |
|
109 thread.start() |
|
110 return thread |
|
111 |
87 |
112 def __processQueue(self): |
88 def __processQueue(self): |
113 """ |
89 """ |
114 Private method to take the next service request and send it to the |
90 Private method to take the next service request and send it to the |
115 client. |
91 client. |