src/eric7/DebugClients/Python/MultiprocessingExtension.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9653
e67609152c5e
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
17 17
18 18
19 def patchMultiprocessing(module, debugClient): 19 def patchMultiprocessing(module, debugClient):
20 """ 20 """
21 Function to patch the multiprocessing module. 21 Function to patch the multiprocessing module.
22 22
23 @param module reference to the imported module to be patched 23 @param module reference to the imported module to be patched
24 @type module 24 @type module
25 @param debugClient reference to the debug client object 25 @param debugClient reference to the debug client object
26 @type DebugClient 26 @type DebugClient
27 """ # __IGNORE_WARNING_D234__ 27 """ # __IGNORE_WARNING_D234__
28 global _debugClient, _originalProcess, _originalBootstrap 28 global _debugClient, _originalProcess, _originalBootstrap
29 29
30 _debugClient = debugClient 30 _debugClient = debugClient
31 31
32 _originalProcess = module.process.BaseProcess 32 _originalProcess = module.process.BaseProcess
33 _originalBootstrap = _originalProcess._bootstrap 33 _originalBootstrap = _originalProcess._bootstrap
34 34
35 class ProcessWrapper(_originalProcess): 35 class ProcessWrapper(_originalProcess):
36 """ 36 """
37 Wrapper class for multiprocessing.Process. 37 Wrapper class for multiprocessing.Process.
38 """ 38 """
39
39 def _bootstrap(self, *args, **kwargs): 40 def _bootstrap(self, *args, **kwargs):
40 """ 41 """
41 Wrapper around _bootstrap to start debugger. 42 Wrapper around _bootstrap to start debugger.
42 43
43 @param args function arguments 44 @param args function arguments
44 @type list 45 @type list
45 @param kwargs keyword only arguments 46 @param kwargs keyword only arguments
46 @type dict 47 @type dict
47 @return exit code of the process 48 @return exit code of the process
48 @rtype int 49 @rtype int
49 """ 50 """
50 _debugging = False 51 _debugging = False
51 if ( 52 if _debugClient.debugging and _debugClient.multiprocessSupport:
52 _debugClient.debugging and
53 _debugClient.multiprocessSupport
54 ):
55 scriptName = sys.argv[0] 53 scriptName = sys.argv[0]
56 if not _debugClient.skipMultiProcessDebugging(scriptName): 54 if not _debugClient.skipMultiProcessDebugging(scriptName):
57 _debugging = True 55 _debugging = True
58 try: 56 try:
59 (wd, host, port, exceptions, tracePython, redirect, 57 (
60 noencoding) = _debugClient.startOptions[:7] 58 wd,
59 host,
60 port,
61 exceptions,
62 tracePython,
63 redirect,
64 noencoding,
65 ) = _debugClient.startOptions[:7]
61 _debugClient.startDebugger( 66 _debugClient.startDebugger(
62 sys.argv[0], host=host, port=port, 67 sys.argv[0],
63 exceptions=exceptions, tracePython=tracePython, 68 host=host,
64 redirect=redirect, passive=False, 69 port=port,
65 multiprocessSupport=True 70 exceptions=exceptions,
71 tracePython=tracePython,
72 redirect=redirect,
73 passive=False,
74 multiprocessSupport=True,
66 ) 75 )
67 except Exception: 76 except Exception:
68 print( 77 print(
69 # __IGNORE_WARNING_M801__ 78 # __IGNORE_WARNING_M801__
70 "Exception during multiprocessing bootstrap init:" 79 "Exception during multiprocessing bootstrap init:"
71 ) 80 )
72 traceback.print_exc(file=sys.stdout) 81 traceback.print_exc(file=sys.stdout)
73 sys.stdout.flush() 82 sys.stdout.flush()
74 raise 83 raise
75 84
76 exitcode = _originalBootstrap(self, *args, **kwargs) 85 exitcode = _originalBootstrap(self, *args, **kwargs)
77 86
78 if _debugging: 87 if _debugging:
79 _debugClient.progTerminated(exitcode, "process finished") 88 _debugClient.progTerminated(exitcode, "process finished")
80 89
81 return exitcode 90 return exitcode
82 91
83 _originalProcess._bootstrap = ProcessWrapper._bootstrap 92 _originalProcess._bootstrap = ProcessWrapper._bootstrap

eric ide

mercurial