[Python-checkins] r47182 - sandbox/trunk/pdb/mconnection.py sandbox/trunk/pdb/mpdb.py

matt.fleming python-checkins at python.org
Fri Jun 30 22:12:22 CEST 2006


Author: matt.fleming
Date: Fri Jun 30 22:12:21 2006
New Revision: 47182

Modified:
   sandbox/trunk/pdb/mconnection.py
   sandbox/trunk/pdb/mpdb.py
Log:
Allow mpdb to use pydb's restart command, both locally and remotely.


Modified: sandbox/trunk/pdb/mconnection.py
==============================================================================
--- sandbox/trunk/pdb/mconnection.py	(original)
+++ sandbox/trunk/pdb/mconnection.py	Fri Jun 30 22:12:21 2006
@@ -126,7 +126,7 @@
     def disconnect(self):
         if self.output is None or self._sock is None:
             return
-        self.output.close()
+        self.output.shutdown(socket.SHUT_RDWR)
         self._sock.close()
         self._sock = None
         self.listening = False

Modified: sandbox/trunk/pdb/mpdb.py
==============================================================================
--- sandbox/trunk/pdb/mpdb.py	(original)
+++ sandbox/trunk/pdb/mpdb.py	Fri Jun 30 22:12:21 2006
@@ -111,7 +111,8 @@
         ret = self.connection.readline()
         if ret == '':
             self.errmsg('Connection closed unexpectedly')
-            raise Exit
+            self.onecmd = lambda x: pydb.Pdb.onecmd(self, x)
+            self.do_rquit(None)
         # The output from the command that we've just sent to the server
         # is returned along with the prompt of that server. So we keep reading
         # until we find our prompt.
@@ -121,14 +122,34 @@
                 # We're probably _never_ going to get that data and that
                 # connection is probably dead.
                 self.errmsg('Connection died unexpectedly')
-                raise Exit
+                self.onecmd = lambda x: pydb.Pdb.onecmd(self, x)
+                self.do_rquit(None)
             else:
                 ret += self.connection.readline()
                 i += 1
+
+        # Some 'special' actions must be taken depending on the data returned
+        if 'restart_now' in ret:
+            self.connection.write('ACK:restart_now')
+            self.errmsg('Pdbserver restarting..')
+            # We've acknowledged a restart, which means that a new pdbserver
+            # process is started, so we have to connect all over again.
+            self._disconnect()
+            time.sleep(3.0)
+            self.do_target(self.target_addr)
+            return
         self.msg_nocr(ret)
         self.lastcmd = line
         return
 
+    def _disconnect(self):
+        """ Disconnect a connection. """
+        self.connection.disconnect()
+        self.connection = None
+        self.target = 'local'
+        if hasattr(self, 'local_prompt'):
+            self.prompt = self.local_prompt
+
     def msg_nocr(self, msg, out=None):
         """Common routine for reporting messages. Derived classes may want
         to override this to capture output.
@@ -248,7 +269,7 @@
             return
         if self.target == 'remote':
             self.errmsg('Already connected to a remote machine.')
-            return 
+            return
         if target == 'tcp':
             # TODO: need to save state of current debug session
             if self.connection: self.connection.disconnect()
@@ -301,6 +322,7 @@
         # in remote_onecmd, because it may be different to this client's.
         self.local_prompt = self.prompt
         self.prompt = ""
+        self.target_addr = target + " " + addr
         line = self.connection.readline()
         if line == '':
             self.errmsg('Connection closed unexpectedly')
@@ -382,6 +404,7 @@
         except ConnectionFailed, err:
             self.errmsg("Failed to connect to %s: (%s)" % (comm, err))
             return
+        self.pdbserver_addr = comm
         self.target = 'remote'
         self._rebind_input(self.connection)
         self._rebind_output(self.connection)
@@ -395,15 +418,33 @@
             return
         self._rebind_output(self.orig_stdout)
         self._rebind_input(self.orig_stdin)
-        if self.connection != None:
-            self.connection.disconnect()
-        if hasattr(self, 'local_prompt'):
-            self.prompt = self.local_prompt
-        self.msg('Exiting remote debugging...')
+        self._disconnect()
         self.target = 'local'
         self.do_quit(None)
         raise Exit
 
+    def do_restart(self, arg):
+        """ Extend pydb.do_restart to signal to any clients connected on
+        a debugger's connection that this debugger is going to be restarted.
+        All state is lost, and a new copy of the debugger is used.
+        """
+        # We don't proceed with the restart until the action has been
+        # ACK'd by any connected clients
+        if self.connection != None:
+            self.msg('restart_now\n(MPdb)')
+            line = ""
+            while not 'ACK:restart_now' in line:
+                line = self.connection.readline()
+            try:
+                self.do_rquit(None)
+            except Exit:
+                pass
+        else:
+            self.msg("Re exec'ing\n\t%s" % self._sys_argv)
+        os.execvp(self._sys_argv[0], self._sys_argv)
+            
+        
+
     def do_thread(self, arg):
         """Use this command to switch between threads.
 The new thread ID must be currently known.


More information about the Python-checkins mailing list