eric6/DebugClients/Python/DebugClientBase.py

branch
multi_processing
changeset 7407
a0b6acee2c20
parent 7405
bf6be3cff6cf
child 7409
1413bfe73d41
equal deleted inserted replaced
7405:bf6be3cff6cf 7407:a0b6acee2c20
2073 if enableTrace: 2073 if enableTrace:
2074 self.mainThread.set_trace() 2074 self.mainThread.set_trace()
2075 2075
2076 def startProgInDebugger(self, progargs, wd='', host=None, 2076 def startProgInDebugger(self, progargs, wd='', host=None,
2077 port=None, exceptions=True, tracePython=False, 2077 port=None, exceptions=True, tracePython=False,
2078 redirect=True): 2078 redirect=True, passive=True):
2079 """ 2079 """
2080 Public method used to start the remote debugger. 2080 Public method used to start the remote debugger.
2081 2081
2082 @param progargs commandline for the program to be debugged 2082 @param progargs commandline for the program to be debugged
2083 (list of strings) 2083 (list of strings)
2088 (boolean) 2088 (boolean)
2089 @param tracePython flag to enable tracing into the Python library 2089 @param tracePython flag to enable tracing into the Python library
2090 (boolean) 2090 (boolean)
2091 @param redirect flag indicating redirection of stdin, stdout and 2091 @param redirect flag indicating redirection of stdin, stdout and
2092 stderr (boolean) 2092 stderr (boolean)
2093 @param passive flag indicating a passive debugging session
2094 @type bool
2093 """ 2095 """
2094 if host is None: 2096 if host is None:
2095 host = os.getenv('ERICHOST', 'localhost') 2097 host = os.getenv('ERICHOST', 'localhost')
2096 if port is None: 2098 if port is None:
2097 port = os.getenv('ERICPORT', 42424) 2099 port = os.getenv('ERICPORT', 42424)
2110 os.chdir(wd) 2112 os.chdir(wd)
2111 self.running = sys.argv[0] 2113 self.running = sys.argv[0]
2112 self.__setCoding(self.running) 2114 self.__setCoding(self.running)
2113 self.debugging = True 2115 self.debugging = True
2114 2116
2115 self.passive = True 2117 self.passive = passive
2116 self.sendPassiveStartup(self.running, exceptions) 2118 if passive:
2119 self.sendPassiveStartup(self.running, exceptions)
2117 self.__interact() 2120 self.__interact()
2118 2121
2119 self.attachThread(mainThread=True) 2122 self.attachThread(mainThread=True)
2120 self.mainThread.tracePythonLibs(tracePython) 2123 self.mainThread.tracePythonLibs(tracePython)
2121 2124
2123 # we report on all unhandled exceptions 2126 # we report on all unhandled exceptions
2124 sys.excepthook = self.__unhandled_exception 2127 sys.excepthook = self.__unhandled_exception
2125 self.__interceptSignals() 2128 self.__interceptSignals()
2126 2129
2127 # This will eventually enter a local event loop. 2130 # This will eventually enter a local event loop.
2128 # Note the use of backquotes to cause a repr of self.running. The
2129 # need for this is on Windows os where backslash is the path separator.
2130 # They will get inadvertantly stripped away during the eval causing
2131 # IOErrors if self.running is passed as a normal str.
2132 self.debugMod.__dict__['__file__'] = self.running 2131 self.debugMod.__dict__['__file__'] = self.running
2133 sys.modules['__main__'] = self.debugMod 2132 sys.modules['__main__'] = self.debugMod
2134 res = self.mainThread.run( 2133 code = self.__compileFileSource(self.running)
2135 'exec(open(' + repr(self.running) + ').read())', 2134 if code:
2136 self.debugMod.__dict__) 2135 res = self.mainThread.run(code, self.debugMod.__dict__, debug=True)
2137 self.progTerminated(res) 2136 self.progTerminated(res)
2137 else:
2138 self.progTerminated(42) # should not happen
2138 2139
2139 def run_call(self, scriptname, func, *args): 2140 def run_call(self, scriptname, func, *args):
2140 """ 2141 """
2141 Public method used to start the remote debugger and call a function. 2142 Public method used to start the remote debugger and call a function.
2142 2143
2187 port = None 2188 port = None
2188 wd = '' 2189 wd = ''
2189 tracePython = False 2190 tracePython = False
2190 exceptions = True 2191 exceptions = True
2191 redirect = True 2192 redirect = True
2193 passive = True
2192 while args[0]: 2194 while args[0]:
2193 if args[0] == '-h': 2195 if args[0] == '-h':
2194 host = args[1] 2196 host = args[1]
2195 del args[0] 2197 del args[0]
2196 del args[0] 2198 del args[0]
2220 del args[0] 2222 del args[0]
2221 elif args[0] == '--fork-parent': 2223 elif args[0] == '--fork-parent':
2222 self.fork_auto = True 2224 self.fork_auto = True
2223 self.fork_child = False 2225 self.fork_child = False
2224 del args[0] 2226 del args[0]
2227 elif args[0] == '--no-passive':
2228 passive = False
2229 del args[0]
2225 elif args[0] == '--': 2230 elif args[0] == '--':
2226 del args[0] 2231 del args[0]
2227 break 2232 break
2228 else: # unknown option 2233 else: # unknown option
2229 del args[0] 2234 del args[0]
2230 if not args: 2235 if not args:
2231 print("No program given. Aborting!") 2236 print("No program given. Aborting!")
2237 # __IGNORE_WARNING_M801__
2238 elif "-m" in args:
2239 print("Running module as a script is not supported. Aborting!")
2232 # __IGNORE_WARNING_M801__ 2240 # __IGNORE_WARNING_M801__
2233 else: 2241 else:
2234 # Store options if a process is spawn 2242 # Store options if a process is spawn
2235 # TODO: check which ones are really needed 2243 # TODO: check which ones are really needed
2236 self.startOptions = ( 2244 self.startOptions = (
2240 if not self.noencoding: 2248 if not self.noencoding:
2241 self.__coding = self.defaultCoding 2249 self.__coding = self.defaultCoding
2242 self.startProgInDebugger(args, wd, host, port, 2250 self.startProgInDebugger(args, wd, host, port,
2243 exceptions=exceptions, 2251 exceptions=exceptions,
2244 tracePython=tracePython, 2252 tracePython=tracePython,
2245 redirect=redirect) 2253 redirect=redirect,
2254 passive=passive)
2246 else: 2255 else:
2247 if sys.argv[1] == '--no-encoding': 2256 if sys.argv[1] == '--no-encoding':
2248 self.noencoding = True 2257 self.noencoding = True
2249 del sys.argv[1] 2258 del sys.argv[1]
2250 2259

eric ide

mercurial