6 """ |
6 """ |
7 Module implementing a function to patch the process creation functions to |
7 Module implementing a function to patch the process creation functions to |
8 support multiprocess debugging. |
8 support multiprocess debugging. |
9 """ |
9 """ |
10 |
10 |
|
11 import contextlib |
11 |
12 |
12 from DebugUtilities import ( |
13 from DebugUtilities import ( |
13 patchArguments, patchArgumentStringWindows, isPythonProgram, |
14 patchArguments, patchArgumentStringWindows, isPythonProgram, |
14 isWindowsPlatform |
15 isWindowsPlatform |
15 ) |
16 ) |
304 |
305 |
305 frame = frame.f_back |
306 frame = frame.f_back |
306 frame = None # Just make sure we don't hold on to it. |
307 frame = None # Just make sure we don't hold on to it. |
307 |
308 |
308 childProcess = getattr(os, originalName)() # fork |
309 childProcess = getattr(os, originalName)() # fork |
309 if not childProcess and not isMultiprocessingPopen: |
310 if ( |
310 if isNewPythonProcess: |
311 not childProcess and |
311 (wd, host, port, exceptions, tracePython, redirect, |
312 not isMultiprocessingPopen and |
312 noencoding) = _debugClient.startOptions |
313 isNewPythonProcess |
313 _debugClient.startDebugger( |
314 ): |
314 filename=sys.argv[0], |
315 (wd, host, port, exceptions, tracePython, redirect, |
315 host=host, |
316 noencoding) = _debugClient.startOptions |
316 port=port, |
317 _debugClient.startDebugger( |
317 enableTrace=multiprocess and not isSubprocessFork, |
318 filename=sys.argv[0], |
318 exceptions=exceptions, |
319 host=host, |
319 tracePython=tracePython, |
320 port=port, |
320 redirect=redirect, |
321 enableTrace=multiprocess and not isSubprocessFork, |
321 passive=False, |
322 exceptions=exceptions, |
322 multiprocessSupport=multiprocess) |
323 tracePython=tracePython, |
|
324 redirect=redirect, |
|
325 passive=False, |
|
326 multiprocessSupport=multiprocess) |
323 return childProcess |
327 return childProcess |
324 |
328 |
325 return newFork |
329 return newFork |
326 |
330 |
327 |
331 |
399 except ImportError: |
403 except ImportError: |
400 import _winapi as _subprocess |
404 import _winapi as _subprocess |
401 patchModule(_subprocess, 'CreateProcess', createCreateProcess) |
405 patchModule(_subprocess, 'CreateProcess', createCreateProcess) |
402 else: |
406 else: |
403 patchModule(os, "fork", createFork) |
407 patchModule(os, "fork", createFork) |
404 try: |
408 with contextlib.suppress(ImportError): |
405 import _posixsubprocess |
409 import _posixsubprocess |
406 patchModule(_posixsubprocess, "fork_exec", createForkExec) |
410 patchModule(_posixsubprocess, "fork_exec", createForkExec) |
407 except ImportError: |
|
408 pass |
|
409 |
411 |
410 _debugClient = debugClient |
412 _debugClient = debugClient |