diff options
Diffstat (limited to 'Lib/idlelib/run.py')
-rw-r--r-- | Lib/idlelib/run.py | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py index 9f26c16..5db652e 100644 --- a/Lib/idlelib/run.py +++ b/Lib/idlelib/run.py @@ -1,13 +1,44 @@ import sys +import time +import socket import rpc def main(): + """Start the Python execution server in a subprocess + + In Idle, RPCServer is instantiated with handlerclass MyHandler, which + inherits register/unregister methods from RPCHandler via the mix-in class + SocketIO. + + When the RPCServer is instantiated, the TCPServer initialization creates an + instance of run.MyHandler and calls its handle() method. handle() + instantiates a run.Executive, passing it a reference to the MyHandler + object. That reference is saved as an attribute of the Executive instance. + The Executive methods have access to the reference and can pass it on to + entities that they command (e.g. RemoteDebugger.Debugger.start_debugger()). + The latter, in turn, can call MyHandler(SocketIO) register/unregister + methods via the reference to register and unregister themselves. + + """ port = 8833 if sys.argv[1:]: port = int(sys.argv[1]) sys.argv[:] = [""] addr = ("localhost", port) - svr = rpc.RPCServer(addr, MyHandler) + for i in range(12): + time.sleep(i) + try: + svr = rpc.RPCServer(addr, MyHandler) + break + except socket.error, err: + if i < 5: + print>>sys.__stderr__, ".. ", + else: + print>>sys.__stderr__,"\nPython subprocess socket error: "\ + + err[1] + ", retrying...." + else: + print>>sys.__stderr__, "\nConnection to Idle failed, exiting." + sys.exit() svr.handle_request() # A single request only class MyHandler(rpc.RPCHandler): |