eric6/DebugClients/Python/DebugClientBase.py

branch
multi_processing
changeset 7409
1413bfe73d41
parent 7407
a0b6acee2c20
child 7411
6d8dcb3551b3
diff -r 0d58e708f57b -r 1413bfe73d41 eric6/DebugClients/Python/DebugClientBase.py
--- a/eric6/DebugClients/Python/DebugClientBase.py	Mon Feb 10 19:49:45 2020 +0100
+++ b/eric6/DebugClients/Python/DebugClientBase.py	Tue Feb 11 18:58:38 2020 +0100
@@ -231,6 +231,7 @@
         self.running = None
         self.test = None
         self.debugging = False
+        self.multiprocessSupport = False
         
         self.fork_auto = False
         self.fork_child = False
@@ -327,6 +328,7 @@
             pass
 
         self.debugging = False
+        self.multiprocessSupport = False
         
         # make sure we close down our end of the socket
         # might be overkill as normally stdin, stdout and stderr
@@ -489,6 +491,7 @@
             
             self.running = sys.argv[0]
             self.debugging = True
+            self.multiprocessSupport = params["multiprocess"]
             
             self.fork_auto = params["autofork"]
             self.fork_child = params["forkChild"]
@@ -1308,7 +1311,8 @@
         if self.errorstream in wrdy:
             self.writeReady(self.errorstream)
     
-    def connectDebugger(self, port, remoteAddress=None, redirect=True):
+    def connectDebugger(self, port, remoteAddress=None, redirect=True,
+                        name=""):
         """
         Public method to establish a session with the debugger.
         
@@ -1316,11 +1320,15 @@
         stdout and stderr and saves these file objects in case the application
         being debugged redirects them itself.
         
-        @param port the port number to connect to (int)
+        @param port the port number to connect to
+        @type int
         @param remoteAddress the network address of the debug server host
-            (string)
+        @type str
         @param redirect flag indicating redirection of stdin, stdout and
-            stderr (boolean)
+            stderr
+        @type bool
+        @param name name to be attached to the debugger ID
+        @type str
         """
         if remoteAddress is None:
             remoteAddress = "127.0.0.1"
@@ -1328,7 +1336,11 @@
             remoteAddress = remoteAddress.split("@@i")[0]
         sock = socket.create_connection((remoteAddress, port))
         
-        self.__debuggerId = "{0}-{1}".format(socket.gethostname(), os.getpid())
+        if not name:
+            name = "main"
+        self.__debuggerId = "{0}-{1}-{2}".format(
+            socket.gethostname(), os.getpid(), name
+        )
         
         name = sys.stdin.name
         # Special case if in a multiprocessing.Process
@@ -2010,10 +2022,10 @@
                 comp = completer(text, state)
             except Exception:
                 comp = None
-
+    
     def startDebugger(self, filename=None, host=None, port=None,
                       enableTrace=True, exceptions=True, tracePython=False,
-                      redirect=True, passive=True):
+                      redirect=True, passive=True, multiprocessSupport=False):
         """
         Public method used to start the remote debugger.
         
@@ -2034,6 +2046,9 @@
         @type bool
         @param passive flag indicating a passive debugging session
         @type bool
+        @param multiprocessSupport flag indicating to enable multiprocess
+            debugging support
+        @type bool
         """
         if host is None:
             host = os.getenv('ERICHOST', 'localhost')
@@ -2041,7 +2056,11 @@
             port = os.getenv('ERICPORT', 42424)
         
         remoteAddress = self.__resolveHost(host)
-        self.connectDebugger(port, remoteAddress, redirect)
+        if filename is not None:
+            name = os.path.basename(filename)
+        else:
+            name = ""
+        self.connectDebugger(port, remoteAddress, redirect, name=name)
         if filename is not None:
             self.running = os.path.abspath(filename)
         else:
@@ -2075,7 +2094,8 @@
     
     def startProgInDebugger(self, progargs, wd='', host=None,
                             port=None, exceptions=True, tracePython=False,
-                            redirect=True, passive=True):
+                            redirect=True, passive=True,
+                            multiprocessSupport=False):
         """
         Public method used to start the remote debugger.
         
@@ -2092,6 +2112,9 @@
             stderr (boolean)
         @param passive flag indicating a passive debugging session
         @type bool
+        @param multiprocessSupport flag indicating to enable multiprocess
+            debugging support
+        @type bool
         """
         if host is None:
             host = os.getenv('ERICHOST', 'localhost')
@@ -2099,7 +2122,8 @@
             port = os.getenv('ERICPORT', 42424)
         
         remoteAddress = self.__resolveHost(host)
-        self.connectDebugger(port, remoteAddress, redirect)
+        name = os.path.basename(progargs[0])
+        self.connectDebugger(port, remoteAddress, redirect, name=name)
         
         self._fncache = {}
         self.dircache = []
@@ -2113,6 +2137,7 @@
         self.running = sys.argv[0]
         self.__setCoding(self.running)
         self.debugging = True
+        self.multiprocessSupport = multiprocessSupport
         
         self.passive = passive
         if passive:
@@ -2191,6 +2216,7 @@
             exceptions = True
             redirect = True
             passive = True
+            multiprocess = False
             while args[0]:
                 if args[0] == '-h':
                     host = args[1]
@@ -2227,6 +2253,9 @@
                 elif args[0] == '--no-passive':
                     passive = False
                     del args[0]
+                elif args[0] == '--multiprocess':
+                    multiprocess = True
+                    del args[0]
                 elif args[0] == '--':
                     del args[0]
                     break
@@ -2251,7 +2280,8 @@
                                          exceptions=exceptions,
                                          tracePython=tracePython,
                                          redirect=redirect,
-                                         passive=passive)
+                                         passive=passive,
+                                         multiprocessSupport=multiprocess)
         else:
             if sys.argv[1] == '--no-encoding':
                 self.noencoding = True

eric ide

mercurial