eric6/DebugClients/Python/QProcessExtension.py

branch
multi_processing
changeset 7412
0a995393d2ba
parent 7411
6d8dcb3551b3
child 7419
9c1163735448
equal deleted inserted replaced
7411:6d8dcb3551b3 7412:0a995393d2ba
8 process. 8 process.
9 """ 9 """
10 10
11 import os 11 import os
12 12
13 from DebugUtilities import isPythonProgram, patchArguments
14
13 _debugClient = None 15 _debugClient = None
14
15
16 def _isPythonProgram(program, arguments):
17 """
18 Protected function to check, if program is a Python interpreter and
19 arguments don't include '-m'.
20
21 @param program program to be executed
22 @type str
23 @param arguments list of command line arguments
24 @type list of str
25 @return flag indicating a python program and a tuple containing the
26 interpreter to be used and the arguments
27 @rtype tuple of (bool, tuple of (str, list of str))
28 """
29 prog = program.lower()
30 ok = (
31 ("python" in prog and arguments[0] != '-m') or
32 "pypy" in prog
33 )
34 return ok, (program, arguments[:])
35 16
36 17
37 def patchQProcess(module, debugClient): 18 def patchQProcess(module, debugClient):
38 """ 19 """
39 Function to patch the QtCore module's QProcess. 20 Function to patch the QtCore module's QProcess.
43 @param debugClient reference to the debug client object 24 @param debugClient reference to the debug client object
44 @type DebugClient 25 @type DebugClient
45 """ # __IGNORE_WARNING_D234__ 26 """ # __IGNORE_WARNING_D234__
46 global _debugClient 27 global _debugClient
47 28
29 # TODO: implement a process tracer
30 # i.e. report which processes are started
48 class QProcessWrapper(module.QProcess): 31 class QProcessWrapper(module.QProcess):
49 """ 32 """
50 Wrapper class for *.QProcess. 33 Wrapper class for *.QProcess.
51 """ 34 """
52 _origQProcessStartDetached = module.QProcess.startDetached 35 _origQProcessStartDetached = module.QProcess.startDetached
54 def __init__(self, parent=None): 37 def __init__(self, parent=None):
55 """ 38 """
56 Constructor 39 Constructor
57 """ 40 """
58 super(QProcessWrapper, self).__init__(parent) 41 super(QProcessWrapper, self).__init__(parent)
59
60 @classmethod
61 def modifyArgs(cls, arguments, multiprocessSupport):
62 """
63 Private method to modify the arguments given to the start method.
64
65 @param arguments list of program arguments
66 @type list of str
67 @return modified argument list
68 @rtype list of str
69 """
70 (wd, host, port, exceptions, tracePython, redirect,
71 noencoding) = _debugClient.startOptions[:7]
72
73 modifiedArguments = [
74 os.path.join(os.path.dirname(__file__), "DebugClient.py"),
75 "-h", host,
76 "-p", str(port),
77 "--no-passive",
78 ]
79
80 if wd:
81 modifiedArguments.extend(["-w", wd])
82 if not exceptions:
83 modifiedArguments.append("-e")
84 if tracePython:
85 modifiedArguments.append("-t")
86 if not redirect:
87 modifiedArguments.append("-n")
88 if noencoding:
89 modifiedArguments.append("--no-encoding")
90 if multiprocessSupport:
91 modifiedArguments.append("--multiprocess")
92 modifiedArguments.append("--")
93 # end the arguments for DebugClient
94 modifiedArguments.extend(arguments)
95
96 return modifiedArguments
97 42
98 ################################################################### 43 ###################################################################
99 ## Handling of 'start(...)' below 44 ## Handling of 'start(...)' below
100 ################################################################### 45 ###################################################################
101 46
131 arguments = self.arguments() 76 arguments = self.arguments()
132 if len(args) == 1: 77 if len(args) == 1:
133 mode = args[0] 78 mode = args[0]
134 else: 79 else:
135 mode = module.QIODevice.ReadWrite 80 mode = module.QIODevice.ReadWrite
136 ok, (program, arguments) = _isPythonProgram(program, arguments) 81 ok, (program, arguments) = isPythonProgram(program, arguments)
137 if ( 82 if (
138 ok and ( 83 ok and (
139 not os.path.basename(arguments[0]) 84 not os.path.basename(arguments[0])
140 in _debugClient.noDebugList 85 in _debugClient.noDebugList
141 ) 86 )
142 ): 87 ):
143 newArgs = self.modifyArgs( 88 newArgs = patchArguments(
144 arguments, _debugClient.multiprocessSupport) 89 arguments, _debugClient.multiprocessSupport)
145 super(QProcessWrapper, self).start(program, newArgs, mode) 90 super(QProcessWrapper, self).start(program, newArgs, mode)
146 else: 91 else:
147 super(QProcessWrapper, self).start(*args, **kwargs) 92 super(QProcessWrapper, self).start(*args, **kwargs)
148 else: 93 else:
195 ): 140 ):
196 program = self.program() 141 program = self.program()
197 arguments = self.arguments() 142 arguments = self.arguments()
198 wd = self.workingDirectory() 143 wd = self.workingDirectory()
199 144
200 ok, (program, arguments) = _isPythonProgram(program, arguments) 145 ok, (program, arguments) = isPythonProgram(program, arguments)
201 if ok: 146 if ok:
202 return QProcessWrapper.startDetachedStatic( 147 return QProcessWrapper.startDetachedStatic(
203 program, arguments, wd) 148 program, arguments, wd)
204 else: 149 else:
205 return super(QProcessWrapper, self).startDetached( 150 return super(QProcessWrapper, self).startDetached(
233 arguments = args[1] 178 arguments = args[1]
234 if len(args) >= 3: 179 if len(args) >= 3:
235 wd = args[2] 180 wd = args[2]
236 else: 181 else:
237 wd = "" 182 wd = ""
238 ok, (program, arguments) = _isPythonProgram(program, arguments) 183 ok, (program, arguments) = isPythonProgram(program, arguments)
239 if ok: 184 if ok:
240 newArgs = QProcessWrapper.modifyArgs( 185 newArgs = patchArguments(
241 arguments, _debugClient.multiprocessSupport) 186 arguments, _debugClient.multiprocessSupport)
242 return QProcessWrapper._origQProcessStartDetached( 187 return QProcessWrapper._origQProcessStartDetached(
243 program, newArgs, wd) 188 program, newArgs, wd)
244 else: 189 else:
245 return QProcessWrapper._origQProcessStartDetached( 190 return QProcessWrapper._origQProcessStartDetached(

eric ide

mercurial