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

matt.fleming python-checkins at python.org
Fri Jun 30 17:15:46 CEST 2006


Author: matt.fleming
Date: Fri Jun 30 17:15:43 2006
New Revision: 47172

Modified:
   sandbox/trunk/pdb/mpdb.py
Log:
Fix: Client connection contiuously in CLOSE_WAIT state.

Modified: sandbox/trunk/pdb/mpdb.py
==============================================================================
--- sandbox/trunk/pdb/mpdb.py	(original)
+++ sandbox/trunk/pdb/mpdb.py	Fri Jun 30 17:15:43 2006
@@ -17,6 +17,7 @@
 import os
 from optparse import OptionParser
 import pydb
+from pydb.gdb import Restart
 import socket
 import sys
 import time
@@ -108,11 +109,22 @@
             return
         self.connection.write(line)
         ret = self.connection.readline()
+        if ret == '':
+            self.errmsg('Connection closed unexpectedly')
+            raise Exit
         # 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.
+        i = 1
         while self.local_prompt not in ret:
-            ret += self.connection.readline()
+            if i == 100:
+                # We're probably _never_ going to get that data and that
+                # connection is probably dead.
+                self.errmsg('Connection died unexpectedly')
+                raise Exit
+            else:
+                ret += self.connection.readline()
+                i += 1
         self.msg_nocr(ret)
         self.lastcmd = line
         return
@@ -290,6 +302,9 @@
         self.local_prompt = self.prompt
         self.prompt = ""
         line = self.connection.readline()
+        if line == '':
+            self.errmsg('Connection closed unexpectedly')
+            raise Exit
         while '(MPdb)' not in line:
             line = self.connection.readline()
         self.msg_nocr(line)
@@ -454,19 +469,23 @@
                             % args[0])
                 return
 
-def pdbserver(addr, args):
+def pdbserver(addr):
     """ This method sets up a pdbserver debugger that allows debuggers
-    to connect to 'address' using 'protocol'. The argument 'filename'
-    is the name of the file that is being debugged.
+    to connect to 'addr', which a protocol-specific address, i.e.
+    tcp = 'tcp mydomainname.com:9876'
+    serial = 'serial /dev/ttyC0'
     """
     m = MPdb()
-    mainpyfile = args[0]
-    m.mainpyfile = mainpyfile
+    m._sys_argv = ['python']
+    for i in sys.argv:
+        m._sys_argv.append(i)
+    m._program_sys_argv = sys.argv[1:]
+    m.mainpyfile = m._program_sys_argv[1]
     m.do_pdbserver(addr)
     while True:
         try:
-            m._runscript(mainpyfile)
-        except pydb.gdb.Restart:
+            m._runscript(m.mainpyfile)
+        except Restart:
             m.msg('Restarting')
         except Exit:
             break
@@ -475,9 +494,8 @@
     """ Connect this debugger to a pdbserver at 'addr'. 'addr' is
     a protocol-specific address. i.e.
     tcp = 'tcp mydomainname.com:9876'
-    serial = '/dev/ttyC0'
+    serial = 'serial /dev/ttyC0'
     """
-    print addr
     m = MPdb()
     # Look Ma, no script!
     m.do_target(addr)
@@ -485,7 +503,7 @@
         try:
             m.cmdloop()
         except:
-            sys.exit()
+            break
 
 def main():
     """ Main entry point to this module. """
@@ -494,7 +512,7 @@
         target(opts.target)
         sys.exit()
     elif opts.pdbserver:
-        pdbserver(opts.pdbserver, args)
+        pdbserver(opts.pdbserver)
         sys.exit()
     else:
         if not opts.scriptname:
@@ -510,10 +528,19 @@
     mpdb = MPdb()
     while 1:
         try:
+            mpdb._sys_argv = ['python']
+            for i in sys.argv:
+                mpdb._sys_argv.append(i)
+            mpdb._program_sys_argv = mpdb._sys_argv[1:]
             mpdb._runscript(mainpyfile)
             if mpdb._user_requested_quit:
                 break
             mpdb.msg("The program finished and will be restarted")
+        except Restart:
+            sys.argv = list(mpdb._program_sys_argv)
+            mpdb.msg('Restarting with %s with arguments:\n\t%s'
+                     % (mpdb.filename(mainpyfile),
+                        ' '.join(mpdb._program_sys_argv[1:])))
         except SystemExit:
             # In most cases SystemExit does not warrant a post-mortem session.
             mpdb.msg("The program exited via sys.exit(). " + \


More information about the Python-checkins mailing list