16 |
16 |
17 |
17 |
18 def patchQProcess(module, debugClient): |
18 def patchQProcess(module, debugClient): |
19 """ |
19 """ |
20 Function to patch the QtCore module's QProcess. |
20 Function to patch the QtCore module's QProcess. |
21 |
21 |
22 @param module reference to the imported module to be patched |
22 @param module reference to the imported module to be patched |
23 @type module |
23 @type module |
24 @param debugClient reference to the debug client object |
24 @param debugClient reference to the debug client object |
25 @type DebugClient |
25 @type DebugClient |
26 """ # __IGNORE_WARNING_D234__ |
26 """ # __IGNORE_WARNING_D234__ |
27 global _debugClient |
27 global _debugClient |
28 |
28 |
29 class QProcessWrapper(module.QProcess): |
29 class QProcessWrapper(module.QProcess): |
30 """ |
30 """ |
31 Wrapper class for *.QProcess. |
31 Wrapper class for *.QProcess. |
32 """ |
32 """ |
|
33 |
33 _origQProcessStartDetached = module.QProcess.startDetached |
34 _origQProcessStartDetached = module.QProcess.startDetached |
34 |
35 |
35 def __init__(self, parent=None): |
36 def __init__(self, parent=None): |
36 """ |
37 """ |
37 Constructor |
38 Constructor |
38 """ |
39 """ |
39 super().__init__(parent) |
40 super().__init__(parent) |
40 |
41 |
41 ################################################################### |
42 ################################################################### |
42 ## Handling of 'start(...)' below |
43 ## Handling of 'start(...)' below |
43 ################################################################### |
44 ################################################################### |
44 |
45 |
45 def start(self, *args, **kwargs): |
46 def start(self, *args, **kwargs): |
46 """ |
47 """ |
47 Public method to start the process. |
48 Public method to start the process. |
48 |
49 |
49 This method patches the arguments such, that a debug client is |
50 This method patches the arguments such, that a debug client is |
50 started for the Python script. A Python script is assumed, if the |
51 started for the Python script. A Python script is assumed, if the |
51 program to be started contains the string 'python'. |
52 program to be started contains the string 'python'. |
52 |
53 |
53 @param args arguments of the start call |
54 @param args arguments of the start call |
54 @type list |
55 @type list |
55 @param kwargs keyword arguments of the start call |
56 @param kwargs keyword arguments of the start call |
56 @type dict |
57 @type dict |
57 """ |
58 """ |
58 if ( |
59 if ( |
59 _debugClient.debugging and |
60 _debugClient.debugging |
60 _debugClient.multiprocessSupport and |
61 and _debugClient.multiprocessSupport |
61 ((len(args) >= 2 and isinstance(args[1], list)) or |
62 and ( |
62 (len(args) == 1 and not isinstance(args[0], str)) or |
63 (len(args) >= 2 and isinstance(args[1], list)) |
63 len(args) == 0) |
64 or (len(args) == 1 and not isinstance(args[0], str)) |
|
65 or len(args) == 0 |
|
66 ) |
64 ): |
67 ): |
65 if len(args) >= 2: |
68 if len(args) >= 2: |
66 program = args[0] |
69 program = args[0] |
67 arguments = args[1] |
70 arguments = args[1] |
68 if len(args) > 2: |
71 if len(args) > 2: |
85 if not _debugClient.skipMultiProcessDebugging(scriptName): |
88 if not _debugClient.skipMultiProcessDebugging(scriptName): |
86 newArgs = patchArguments( |
89 newArgs = patchArguments( |
87 _debugClient, |
90 _debugClient, |
88 [program] + arguments, |
91 [program] + arguments, |
89 ) |
92 ) |
90 super().start( |
93 super().start(newArgs[0], newArgs[1:], mode) |
91 newArgs[0], newArgs[1:], mode) |
|
92 return |
94 return |
93 |
95 |
94 super().start(*args, **kwargs) |
96 super().start(*args, **kwargs) |
95 |
97 |
96 ################################################################### |
98 ################################################################### |
97 ## Handling of 'startDetached(...)' below |
99 ## Handling of 'startDetached(...)' below |
98 ################################################################### |
100 ################################################################### |
99 |
101 |
100 def startDetached(self, *args, **kwargs): |
102 def startDetached(self, *args, **kwargs): |
101 """ |
103 """ |
102 Public method to start the detached process. |
104 Public method to start the detached process. |
103 |
105 |
104 This method patches the arguments such, that a debug client is |
106 This method patches the arguments such, that a debug client is |
105 started for the Python script. A Python script is assumed, if the |
107 started for the Python script. A Python script is assumed, if the |
106 program to be started contains the string 'python'. |
108 program to be started contains the string 'python'. |
107 |
109 |
108 @param args arguments of the start call |
110 @param args arguments of the start call |
109 @type list |
111 @type list |
110 @param kwargs keyword arguments of the start call |
112 @param kwargs keyword arguments of the start call |
111 @type dict |
113 @type dict |
112 @return flag indicating a successful start |
114 @return flag indicating a successful start |
113 @rtype bool |
115 @rtype bool |
114 """ |
116 """ |
115 if isinstance(self, str): |
117 if isinstance(self, str): |
116 return QProcessWrapper.startDetachedStatic( |
118 return QProcessWrapper.startDetachedStatic(self, *args) |
117 self, *args) |
|
118 else: |
119 else: |
119 return self.__startDetached(*args, **kwargs) |
120 return self.__startDetached(*args, **kwargs) |
120 |
121 |
121 def __startDetached(self, *args, **kwargs): |
122 def __startDetached(self, *args, **kwargs): |
122 """ |
123 """ |
123 Private method to start the detached process. |
124 Private method to start the detached process. |
124 |
125 |
125 This method patches the arguments such, that a debug client is |
126 This method patches the arguments such, that a debug client is |
126 started for the Python script. A Python script is assumed, if the |
127 started for the Python script. A Python script is assumed, if the |
127 program to be started contains the string 'python'. |
128 program to be started contains the string 'python'. |
128 |
129 |
129 @param args arguments of the start call |
130 @param args arguments of the start call |
130 @type list |
131 @type list |
131 @param kwargs keyword arguments of the start call |
132 @param kwargs keyword arguments of the start call |
132 @type dict |
133 @type dict |
133 @return flag indicating a successful start |
134 @return flag indicating a successful start |
134 @rtype bool |
135 @rtype bool |
135 """ |
136 """ |
136 if ( |
137 if ( |
137 _debugClient.debugging and |
138 _debugClient.debugging |
138 _debugClient.multiprocessSupport and |
139 and _debugClient.multiprocessSupport |
139 len(args) == 0 |
140 and len(args) == 0 |
140 ): |
141 ): |
141 program = self.program() |
142 program = self.program() |
142 arguments = self.arguments() |
143 arguments = self.arguments() |
143 wd = self.workingDirectory() |
144 wd = self.workingDirectory() |
144 |
145 |
145 ok = isPythonProgram(program) |
146 ok = isPythonProgram(program) |
146 if ok: |
147 if ok: |
147 return QProcessWrapper.startDetachedStatic( |
148 return QProcessWrapper.startDetachedStatic(program, arguments, wd) |
148 program, arguments, wd) |
149 |
149 |
|
150 return super().startDetached(*args, **kwargs) |
150 return super().startDetached(*args, **kwargs) |
151 |
151 |
152 @staticmethod |
152 @staticmethod |
153 def startDetachedStatic(*args, **kwargs): |
153 def startDetachedStatic(*args, **kwargs): |
154 """ |
154 """ |
155 Static method to start the detached process. |
155 Static method to start the detached process. |
156 |
156 |
157 This method patches the arguments such, that a debug client is |
157 This method patches the arguments such, that a debug client is |
158 started for the Python script. A Python script is assumed, if the |
158 started for the Python script. A Python script is assumed, if the |
159 program to be started contains the string 'python'. |
159 program to be started contains the string 'python'. |
160 |
160 |
161 @param args arguments of the start call |
161 @param args arguments of the start call |
162 @type list |
162 @type list |
163 @param kwargs keyword arguments of the start call |
163 @param kwargs keyword arguments of the start call |
164 @type dict |
164 @type dict |
165 @return flag indicating a successful start |
165 @return flag indicating a successful start |
166 @rtype bool |
166 @rtype bool |
167 """ |
167 """ |
168 if ( |
168 if ( |
169 _debugClient.debugging and |
169 _debugClient.debugging |
170 _debugClient.multiprocessSupport and |
170 and _debugClient.multiprocessSupport |
171 (len(args) >= 2 and isinstance(args[1], list)) |
171 and (len(args) >= 2 and isinstance(args[1], list)) |
172 ): |
172 ): |
173 program = args[0] |
173 program = args[0] |
174 arguments = args[1] |
174 arguments = args[1] |
175 if len(args) >= 3: |
175 if len(args) >= 3: |
176 wd = args[2] |
176 wd = args[2] |