From 8dcdb77132563c734c228e815498c47e487f95cf Mon Sep 17 00:00:00 2001 From: "Kurt B. Kaiser" Date: Mon, 5 Aug 2002 03:52:10 +0000 Subject: GvR provided solution to the socket rebinding timeout problem. M PyShell.py M rpc.py M run.py --- Lib/idlelib/PyShell.py | 8 +++----- Lib/idlelib/rpc.py | 1 + Lib/idlelib/run.py | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Lib/idlelib/PyShell.py b/Lib/idlelib/PyShell.py index a0a641b..b483ea8 100644 --- a/Lib/idlelib/PyShell.py +++ b/Lib/idlelib/PyShell.py @@ -198,16 +198,14 @@ class ModifiedInterpreter(InteractiveInterpreter): args = [sys.executable] + w + ["-c", "__import__('run').main()", str(port)] self.rpcpid = os.spawnv(os.P_NOWAIT, args[0], args) - # 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): + # Idle starts listening for connection on localhost + for i in range(6): time.sleep(i) try: self.rpcclt = rpc.RPCClient(addr) break except socket.error, err: - if i < 5: + if i < 3: print>>sys.__stderr__, ". ", else: print>>sys.__stderr__,"\nIdle socket error: " + err[1]\ diff --git a/Lib/idlelib/rpc.py b/Lib/idlelib/rpc.py index 267dd60..5bb0e64 100644 --- a/Lib/idlelib/rpc.py +++ b/Lib/idlelib/rpc.py @@ -403,6 +403,7 @@ class RPCClient(SocketIO): def __init__(self, address, family=socket.AF_INET, type=socket.SOCK_STREAM): self.sock = socket.socket(family, type) + self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.sock.bind(address) self.sock.listen(1) diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py index cc3edf1..9ede2ff 100644 --- a/Lib/idlelib/run.py +++ b/Lib/idlelib/run.py @@ -26,13 +26,13 @@ def main(): port = int(sys.argv[1]) sys.argv[:] = [""] addr = ("localhost", port) - for i in range(12): + for i in range(6): time.sleep(i) try: svr = rpc.RPCServer(addr, MyHandler) break except socket.error, err: - if i < 5: + if i < 3: print>>sys.__stderr__, ".. ", else: print>>sys.__stderr__,"\nPython subprocess socket error: "\ -- cgit v0.12