=== modified file 'Lib/idlelib/PyShell.py' --- Lib/idlelib/PyShell.py 2008-10-16 19:40:14 +0000 +++ Lib/idlelib/PyShell.py 2008-12-01 23:10:04 +0000 @@ -342,17 +342,21 @@ InteractiveInterpreter.__init__(self, locals=locals) self.save_warnings_filters = None self.restarting = False - self.subprocess_arglist = self.build_subprocess_arglist() + self.subprocess_arglist = None + self.port = None - port = 8833 rpcclt = None rpcpid = None def spawn_subprocess(self): + if self.subprocess_arglist==None: + self.subprocess_arglist = self.build_subprocess_arglist() args = self.subprocess_arglist self.rpcpid = os.spawnv(os.P_NOWAIT, sys.executable, args) def build_subprocess_arglist(self): + assert (self.port!=0 and self.port!=None), ( + "Socket should have been assigned a port number.") w = ['-W' + s for s in sys.warnoptions] if 1/2 > 0: # account for new division w.append('-Qnew') @@ -373,21 +377,19 @@ return [decorated_exec] + w + ["-c", command, str(self.port)] def start_subprocess(self): - # spawning first avoids passing a listening socket to the subprocess - self.spawn_subprocess() - #time.sleep(20) # test to simulate GUI not accepting connection - addr = (LOCALHOST, self.port) + addr = (LOCALHOST, 0) # Idle starts listening for connection on localhost - for i in range(3): - time.sleep(i) - try: - self.rpcclt = MyRPCClient(addr) - break - except socket.error, err: - pass - else: + try: + self.rpcclt = MyRPCClient(addr) + except socket.error, err: self.display_port_binding_error() return None + self.port=self.rpcclt.listening_sock.getsockname()[1] + # Spawning second means we pass a listening socket to the + # subprocess, which isn't ideal, but otherwise we don't know + # what port the socket got assigned to. + self.spawn_subprocess() + #time.sleep(20) # test to simulate GUI not accepting connection # Accept the connection from the Python execution server self.rpcclt.listening_sock.settimeout(10) try: @@ -754,10 +756,10 @@ def display_port_binding_error(self): tkMessageBox.showerror( "Port Binding Error", - "IDLE can't bind TCP/IP port 8833, which is necessary to " - "communicate with its Python execution server. Either " - "no networking is installed on this computer or another " - "process (another IDLE?) is using the port. Run IDLE with the -n " + "IDLE can't bind to a TCP/IP port, which is necessary to " + "communicate with its Python execution server. This might be " + "because no networking is installed on this computer. " + "Run IDLE with the -n " "command line switch to start without a subprocess and refer to " "Help/IDLE Help 'Running without a subprocess' for further " "details.", === modified file 'Lib/idlelib/rpc.py' --- Lib/idlelib/rpc.py 2008-05-25 07:20:14 +0000 +++ Lib/idlelib/rpc.py 2008-12-01 23:29:03 +0000 @@ -518,8 +518,6 @@ def __init__(self, address, family=socket.AF_INET, type=socket.SOCK_STREAM): self.listening_sock = socket.socket(family, type) - self.listening_sock.setsockopt(socket.SOL_SOCKET, - socket.SO_REUSEADDR, 1) self.listening_sock.bind(address) self.listening_sock.listen(1)