eric6/DebugClients/Python/DebugClientBase.py

branch
multi_processing
changeset 7409
1413bfe73d41
parent 7407
a0b6acee2c20
child 7411
6d8dcb3551b3
equal deleted inserted replaced
7408:0d58e708f57b 7409:1413bfe73d41
229 self.dircache = [] 229 self.dircache = []
230 self.passive = False # used to indicate the passive mode 230 self.passive = False # used to indicate the passive mode
231 self.running = None 231 self.running = None
232 self.test = None 232 self.test = None
233 self.debugging = False 233 self.debugging = False
234 self.multiprocessSupport = False
234 235
235 self.fork_auto = False 236 self.fork_auto = False
236 self.fork_child = False 237 self.fork_child = False
237 238
238 self.readstream = None 239 self.readstream = None
325 self.set_quit() 326 self.set_quit()
326 except Exception: 327 except Exception:
327 pass 328 pass
328 329
329 self.debugging = False 330 self.debugging = False
331 self.multiprocessSupport = False
330 332
331 # make sure we close down our end of the socket 333 # make sure we close down our end of the socket
332 # might be overkill as normally stdin, stdout and stderr 334 # might be overkill as normally stdin, stdout and stderr
333 # SHOULD be closed on exit, but it does not hurt to do it here 335 # SHOULD be closed on exit, but it does not hurt to do it here
334 self.readstream.close(True) 336 self.readstream.close(True)
487 else: 489 else:
488 os.chdir(params["workdir"]) 490 os.chdir(params["workdir"])
489 491
490 self.running = sys.argv[0] 492 self.running = sys.argv[0]
491 self.debugging = True 493 self.debugging = True
494 self.multiprocessSupport = params["multiprocess"]
492 495
493 self.fork_auto = params["autofork"] 496 self.fork_auto = params["autofork"]
494 self.fork_child = params["forkChild"] 497 self.fork_child = params["forkChild"]
495 498
496 self.threads.clear() 499 self.threads.clear()
1306 self.writeReady(self.writestream) 1309 self.writeReady(self.writestream)
1307 1310
1308 if self.errorstream in wrdy: 1311 if self.errorstream in wrdy:
1309 self.writeReady(self.errorstream) 1312 self.writeReady(self.errorstream)
1310 1313
1311 def connectDebugger(self, port, remoteAddress=None, redirect=True): 1314 def connectDebugger(self, port, remoteAddress=None, redirect=True,
1315 name=""):
1312 """ 1316 """
1313 Public method to establish a session with the debugger. 1317 Public method to establish a session with the debugger.
1314 1318
1315 It opens a network connection to the debugger, connects it to stdin, 1319 It opens a network connection to the debugger, connects it to stdin,
1316 stdout and stderr and saves these file objects in case the application 1320 stdout and stderr and saves these file objects in case the application
1317 being debugged redirects them itself. 1321 being debugged redirects them itself.
1318 1322
1319 @param port the port number to connect to (int) 1323 @param port the port number to connect to
1324 @type int
1320 @param remoteAddress the network address of the debug server host 1325 @param remoteAddress the network address of the debug server host
1321 (string) 1326 @type str
1322 @param redirect flag indicating redirection of stdin, stdout and 1327 @param redirect flag indicating redirection of stdin, stdout and
1323 stderr (boolean) 1328 stderr
1329 @type bool
1330 @param name name to be attached to the debugger ID
1331 @type str
1324 """ 1332 """
1325 if remoteAddress is None: 1333 if remoteAddress is None:
1326 remoteAddress = "127.0.0.1" 1334 remoteAddress = "127.0.0.1"
1327 elif "@@i" in remoteAddress: 1335 elif "@@i" in remoteAddress:
1328 remoteAddress = remoteAddress.split("@@i")[0] 1336 remoteAddress = remoteAddress.split("@@i")[0]
1329 sock = socket.create_connection((remoteAddress, port)) 1337 sock = socket.create_connection((remoteAddress, port))
1330 1338
1331 self.__debuggerId = "{0}-{1}".format(socket.gethostname(), os.getpid()) 1339 if not name:
1340 name = "main"
1341 self.__debuggerId = "{0}-{1}-{2}".format(
1342 socket.gethostname(), os.getpid(), name
1343 )
1332 1344
1333 name = sys.stdin.name 1345 name = sys.stdin.name
1334 # Special case if in a multiprocessing.Process 1346 # Special case if in a multiprocessing.Process
1335 if isinstance(name, int): 1347 if isinstance(name, int):
1336 name = '<stdin>' 1348 name = '<stdin>'
2008 state += 1 2020 state += 1
2009 try: 2021 try:
2010 comp = completer(text, state) 2022 comp = completer(text, state)
2011 except Exception: 2023 except Exception:
2012 comp = None 2024 comp = None
2013 2025
2014 def startDebugger(self, filename=None, host=None, port=None, 2026 def startDebugger(self, filename=None, host=None, port=None,
2015 enableTrace=True, exceptions=True, tracePython=False, 2027 enableTrace=True, exceptions=True, tracePython=False,
2016 redirect=True, passive=True): 2028 redirect=True, passive=True, multiprocessSupport=False):
2017 """ 2029 """
2018 Public method used to start the remote debugger. 2030 Public method used to start the remote debugger.
2019 2031
2020 @param filename the program to be debugged 2032 @param filename the program to be debugged
2021 @type str 2033 @type str
2032 @param redirect flag indicating redirection of stdin, stdout and 2044 @param redirect flag indicating redirection of stdin, stdout and
2033 stderr 2045 stderr
2034 @type bool 2046 @type bool
2035 @param passive flag indicating a passive debugging session 2047 @param passive flag indicating a passive debugging session
2036 @type bool 2048 @type bool
2049 @param multiprocessSupport flag indicating to enable multiprocess
2050 debugging support
2051 @type bool
2037 """ 2052 """
2038 if host is None: 2053 if host is None:
2039 host = os.getenv('ERICHOST', 'localhost') 2054 host = os.getenv('ERICHOST', 'localhost')
2040 if port is None: 2055 if port is None:
2041 port = os.getenv('ERICPORT', 42424) 2056 port = os.getenv('ERICPORT', 42424)
2042 2057
2043 remoteAddress = self.__resolveHost(host) 2058 remoteAddress = self.__resolveHost(host)
2044 self.connectDebugger(port, remoteAddress, redirect) 2059 if filename is not None:
2060 name = os.path.basename(filename)
2061 else:
2062 name = ""
2063 self.connectDebugger(port, remoteAddress, redirect, name=name)
2045 if filename is not None: 2064 if filename is not None:
2046 self.running = os.path.abspath(filename) 2065 self.running = os.path.abspath(filename)
2047 else: 2066 else:
2048 try: 2067 try:
2049 self.running = os.path.abspath(sys.argv[0]) 2068 self.running = os.path.abspath(sys.argv[0])
2073 if enableTrace: 2092 if enableTrace:
2074 self.mainThread.set_trace() 2093 self.mainThread.set_trace()
2075 2094
2076 def startProgInDebugger(self, progargs, wd='', host=None, 2095 def startProgInDebugger(self, progargs, wd='', host=None,
2077 port=None, exceptions=True, tracePython=False, 2096 port=None, exceptions=True, tracePython=False,
2078 redirect=True, passive=True): 2097 redirect=True, passive=True,
2098 multiprocessSupport=False):
2079 """ 2099 """
2080 Public method used to start the remote debugger. 2100 Public method used to start the remote debugger.
2081 2101
2082 @param progargs commandline for the program to be debugged 2102 @param progargs commandline for the program to be debugged
2083 (list of strings) 2103 (list of strings)
2090 (boolean) 2110 (boolean)
2091 @param redirect flag indicating redirection of stdin, stdout and 2111 @param redirect flag indicating redirection of stdin, stdout and
2092 stderr (boolean) 2112 stderr (boolean)
2093 @param passive flag indicating a passive debugging session 2113 @param passive flag indicating a passive debugging session
2094 @type bool 2114 @type bool
2115 @param multiprocessSupport flag indicating to enable multiprocess
2116 debugging support
2117 @type bool
2095 """ 2118 """
2096 if host is None: 2119 if host is None:
2097 host = os.getenv('ERICHOST', 'localhost') 2120 host = os.getenv('ERICHOST', 'localhost')
2098 if port is None: 2121 if port is None:
2099 port = os.getenv('ERICPORT', 42424) 2122 port = os.getenv('ERICPORT', 42424)
2100 2123
2101 remoteAddress = self.__resolveHost(host) 2124 remoteAddress = self.__resolveHost(host)
2102 self.connectDebugger(port, remoteAddress, redirect) 2125 name = os.path.basename(progargs[0])
2126 self.connectDebugger(port, remoteAddress, redirect, name=name)
2103 2127
2104 self._fncache = {} 2128 self._fncache = {}
2105 self.dircache = [] 2129 self.dircache = []
2106 sys.argv = progargs[:] 2130 sys.argv = progargs[:]
2107 sys.argv[0] = os.path.abspath(sys.argv[0]) 2131 sys.argv[0] = os.path.abspath(sys.argv[0])
2111 else: 2135 else:
2112 os.chdir(wd) 2136 os.chdir(wd)
2113 self.running = sys.argv[0] 2137 self.running = sys.argv[0]
2114 self.__setCoding(self.running) 2138 self.__setCoding(self.running)
2115 self.debugging = True 2139 self.debugging = True
2140 self.multiprocessSupport = multiprocessSupport
2116 2141
2117 self.passive = passive 2142 self.passive = passive
2118 if passive: 2143 if passive:
2119 self.sendPassiveStartup(self.running, exceptions) 2144 self.sendPassiveStartup(self.running, exceptions)
2120 self.__interact() 2145 self.__interact()
2189 wd = '' 2214 wd = ''
2190 tracePython = False 2215 tracePython = False
2191 exceptions = True 2216 exceptions = True
2192 redirect = True 2217 redirect = True
2193 passive = True 2218 passive = True
2219 multiprocess = False
2194 while args[0]: 2220 while args[0]:
2195 if args[0] == '-h': 2221 if args[0] == '-h':
2196 host = args[1] 2222 host = args[1]
2197 del args[0] 2223 del args[0]
2198 del args[0] 2224 del args[0]
2225 self.fork_child = False 2251 self.fork_child = False
2226 del args[0] 2252 del args[0]
2227 elif args[0] == '--no-passive': 2253 elif args[0] == '--no-passive':
2228 passive = False 2254 passive = False
2229 del args[0] 2255 del args[0]
2256 elif args[0] == '--multiprocess':
2257 multiprocess = True
2258 del args[0]
2230 elif args[0] == '--': 2259 elif args[0] == '--':
2231 del args[0] 2260 del args[0]
2232 break 2261 break
2233 else: # unknown option 2262 else: # unknown option
2234 del args[0] 2263 del args[0]
2249 self.__coding = self.defaultCoding 2278 self.__coding = self.defaultCoding
2250 self.startProgInDebugger(args, wd, host, port, 2279 self.startProgInDebugger(args, wd, host, port,
2251 exceptions=exceptions, 2280 exceptions=exceptions,
2252 tracePython=tracePython, 2281 tracePython=tracePython,
2253 redirect=redirect, 2282 redirect=redirect,
2254 passive=passive) 2283 passive=passive,
2284 multiprocessSupport=multiprocess)
2255 else: 2285 else:
2256 if sys.argv[1] == '--no-encoding': 2286 if sys.argv[1] == '--no-encoding':
2257 self.noencoding = True 2287 self.noencoding = True
2258 del sys.argv[1] 2288 del sys.argv[1]
2259 2289

eric ide

mercurial