diff -r 4a9900aef04e -r 9a008ab4811b eric6/DebugClients/Python/MultiProcessDebugExtension.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/eric6/DebugClients/Python/MultiProcessDebugExtension.py Sun Feb 16 19:36:46 2020 +0100 @@ -0,0 +1,90 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2002 - 2020 Detlev Offenbach <detlev@die-offenbachs.de> +# + +""" +Module implementing a function to patch the process creation functions to +support multiprocess debugging. +""" + +import sys + +from DebugUtilities import isWindowsPlatform, patchArguments, isPythonProgram + +_debugClient = None + + +def patchModule(module, functionName, createFunction): + """ + Function to replace a function of a module with a modified one. + + @param module reference to the module + @type types.ModuleType + @param functionName name of the function to be replaced + @type str + @param createFunction function creating the replacement + @type types.FunctionType + """ + if hasattr(module, functionName): + originalName = 'original_' + functionName + if not hasattr(module, originalName): + setattr(module, originalName, getattr(module, functionName)) + setattr(module, functionName, createFunction(originalName)) + + +def createExecl(originalName): + """ + Function to patch the 'execl' process creation functions. + + <ul> + <li>os.execl(path, arg0, arg1, ...)</li> + <li>os.execle(path, arg0, arg1, ..., env)</li> + <li>os.execlp(file, arg0, arg1, ...)</li> + <li>os.execlpe(file, arg0, arg1, ..., env)</li> + </ul> + """ + def newExecl(path, *args): + """ + Function replacing the 'execl' functions of the os module. + """ + print(args) + import os + if ( + _debugClient.debugging and + _debugClient.multiprocessSupport + ): + args = patchArguments(_debugClient, args) + if isPythonProgram(args[0]): + path = args[0] + print(args) + return getattr(os, originalName)(path, *args) + return newExecl + +def patchNewProcessFunctions(multiprocessEnabled, debugClient): + """ + Function to patch the process creation functions to support multiprocess + debugging. + + @param multiprocessEnabled flag indicating multiprocess support + @type bool + @param debugClient reference to the debug client object + @type DebugClient + """ + global _debugClient + + if not multiprocessEnabled: + # return without patching + return + + import os + + # patch 'os.exec...()' functions + patchModule(os, "execl", createExecl) + patchModule(os, "execle", createExecl) + patchModule(os, "execlp", createExecl) + patchModule(os, "execlpe", createExecl) + + # TODO: implement patching of the various functions of the os module + + _debugClient = debugClient