10 |
10 |
11 import os |
11 import os |
12 import shlex |
12 import shlex |
13 |
13 |
14 from DebugUtilities import ( |
14 from DebugUtilities import ( |
15 isPythonProgram, patchArguments, stringToArgumentsWindows, |
15 isPythonProgram, |
16 isWindowsPlatform |
16 patchArguments, |
|
17 stringToArgumentsWindows, |
|
18 isWindowsPlatform, |
17 ) |
19 ) |
18 |
20 |
19 _debugClient = None |
21 _debugClient = None |
20 |
22 |
21 |
23 |
22 def patchSubprocess(module, debugClient): |
24 def patchSubprocess(module, debugClient): |
23 """ |
25 """ |
24 Function to patch the subprocess module. |
26 Function to patch the subprocess module. |
25 |
27 |
26 @param module reference to the imported module to be patched |
28 @param module reference to the imported module to be patched |
27 @type module |
29 @type module |
28 @param debugClient reference to the debug client object |
30 @param debugClient reference to the debug client object |
29 @type DebugClient |
31 @type DebugClient |
30 """ # __IGNORE_WARNING_D234__ |
32 """ # __IGNORE_WARNING_D234__ |
31 global _debugClient |
33 global _debugClient |
32 |
34 |
33 class PopenWrapper(module.Popen): |
35 class PopenWrapper(module.Popen): |
34 """ |
36 """ |
35 Wrapper class for subprocess.Popen. |
37 Wrapper class for subprocess.Popen. |
36 """ |
38 """ |
|
39 |
37 def __init__(self, arguments, *args, **kwargs): |
40 def __init__(self, arguments, *args, **kwargs): |
38 """ |
41 """ |
39 Constructor |
42 Constructor |
40 |
43 |
41 @param arguments command line arguments for the new process |
44 @param arguments command line arguments for the new process |
42 @type list of str or str |
45 @type list of str or str |
43 @param args constructor arguments of Popen |
46 @param args constructor arguments of Popen |
44 @type list |
47 @type list |
45 @param kwargs constructor keyword only arguments of Popen |
48 @param kwargs constructor keyword only arguments of Popen |
46 @type dict |
49 @type dict |
47 """ |
50 """ |
48 if ( |
51 if ( |
49 _debugClient.debugging and |
52 _debugClient.debugging |
50 _debugClient.multiprocessSupport and |
53 and _debugClient.multiprocessSupport |
51 isinstance(arguments, (str, list)) |
54 and isinstance(arguments, (str, list)) |
52 ): |
55 ): |
53 if isinstance(arguments, str): |
56 if isinstance(arguments, str): |
54 # convert to arguments list |
57 # convert to arguments list |
55 arguments = ( |
58 arguments = ( |
56 stringToArgumentsWindows(arguments) |
59 stringToArgumentsWindows(arguments) |
57 if isWindowsPlatform() else |
60 if isWindowsPlatform() |
58 shlex.split(arguments) |
61 else shlex.split(arguments) |
59 ) |
62 ) |
60 else: |
63 else: |
61 # create a copy of the arguments |
64 # create a copy of the arguments |
62 arguments = arguments[:] |
65 arguments = arguments[:] |
63 ok = isPythonProgram(arguments[0]) |
66 ok = isPythonProgram(arguments[0]) |
65 scriptName = os.path.basename(arguments[0]) |
68 scriptName = os.path.basename(arguments[0]) |
66 if not _debugClient.skipMultiProcessDebugging(scriptName): |
69 if not _debugClient.skipMultiProcessDebugging(scriptName): |
67 arguments = patchArguments( |
70 arguments = patchArguments( |
68 _debugClient, arguments, noRedirect=True |
71 _debugClient, arguments, noRedirect=True |
69 ) |
72 ) |
70 |
73 |
71 super().__init__(arguments, *args, **kwargs) |
74 super().__init__(arguments, *args, **kwargs) |
72 |
75 |
73 _debugClient = debugClient |
76 _debugClient = debugClient |
74 module.Popen = PopenWrapper |
77 module.Popen = PopenWrapper |