diff Lib/idlelib/PyShell.py @ 24386:0e27b67247da legacy-trunk

Reverse the RPC socket connection: Python execution server connects to Idle client and localhost origin of connection is verified by client. M PyShell.py M rpc.py M run.py
author Kurt B. Kaiser <kbk@shore.net>
date Fri, 26 Jul 2002 00:06:42 +0000
parents 1723bcdc1e85
children f059d5435d65
line wrap: on
line diff
--- a/Lib/idlelib/PyShell.py	Thu Jul 25 21:11:23 2002 +0000
+++ b/Lib/idlelib/PyShell.py	Fri Jul 26 00:06:42 2002 +0000
@@ -193,24 +193,30 @@
     def spawn_subprocess(self):
         port = 8833
         addr = ("localhost", port)
+        # Spawn the Python execution "server"
         w = ['-W' + s for s in sys.warnoptions]
         args = [sys.executable] + w + ["-c", "__import__('run').main()",
                                        str(port)]
         self.rpcpid = os.spawnv(os.P_NOWAIT, args[0], args)
-        for i in range(5):
+        # Idle starts listening for connection on localhost, retry since
+        # Idle may be restarted before port is available for rebinding
+        # XXX 25 July 2002 KBK Find out what is causing the delayed release!
+        for i in range(12):
             time.sleep(i)
             try:
                 self.rpcclt = rpc.RPCClient(addr)
                 break
             except socket.error, err:
-                if i > 3:
-                    print >>sys.__stderr__, "Socket error:", err, "; retry..."
+                if i < 5:
+                    print>>sys.__stderr__, ". ",
+                else:
+                    print>>sys.__stderr__,"\nIdle socket error: " + err[1]\
+                                                    + ", retrying..."
         else:
-            # XXX Make this a dialog?  #GvR
-            print >>sys.__stderr__, "Can't spawn subprocess!"
-            # XXX Add Stephen's error msg, resolve the two later... KBK 09Jun02
             display_port_binding_error()
             return
+        # Accept the connection from the Python execution server
+        self.rpcclt.accept()
         self.rpcclt.register("stdin", self.tkconsole)
         self.rpcclt.register("stdout", self.tkconsole.stdout)
         self.rpcclt.register("stderr", self.tkconsole.stderr)