MCPcopy Index your code
hub / github.com/python/cpython / main

Function main

Lib/idlelib/run.py:117–193  ·  view source on GitHub ↗

Start the Python execution server in a subprocess In the Python subprocess, RPCServer is instantiated with handlerclass MyHandler, which inherits register/unregister methods from RPCHandler via the mix-in class SocketIO. When the RPCServer 'server' is instantiated, the TCPServer in

(del_exitfunc=False)

Source from the content-addressed store, hash-verified

115interruptible = False
116
117def main(del_exitfunc=False):
118 """Start the Python execution server in a subprocess
119
120 In the Python subprocess, RPCServer is instantiated with handlerclass
121 MyHandler, which inherits register/unregister methods from RPCHandler via
122 the mix-in class SocketIO.
123
124 When the RPCServer 'server' is instantiated, the TCPServer initialization
125 creates an instance of run.MyHandler and calls its handle() method.
126 handle() instantiates a run.Executive object, passing it a reference to the
127 MyHandler object. That reference is saved as attribute rpchandler of the
128 Executive instance. The Executive methods have access to the reference and
129 can pass it on to entities that they command
130 (e.g. debugger_r.Debugger.start_debugger()). The latter, in turn, can
131 call MyHandler(SocketIO) register/unregister methods via the reference to
132 register and unregister themselves.
133
134 """
135 global exit_now
136 global quitting
137 global no_exitfunc
138 no_exitfunc = del_exitfunc
139 #time.sleep(15) # test subprocess not responding
140 try:
141 assert(len(sys.argv) > 1)
142 port = int(sys.argv[-1])
143 except:
144 print("IDLE Subprocess: no IP port passed in sys.argv.",
145 file=sys.__stderr__)
146 return
147
148 capture_warnings(True)
149 sys.argv[:] = [""]
150 threading.Thread(target=manage_socket,
151 name='SockThread',
152 args=((LOCALHOST, port),),
153 daemon=True,
154 ).start()
155
156 while True:
157 try:
158 if exit_now:
159 try:
160 exit()
161 except KeyboardInterrupt:
162 # exiting but got an extra KBI? Try again!
163 continue
164 try:
165 request = rpc.request_queue.get(block=True, timeout=0.05)
166 except queue.Empty:
167 request = None
168 # Issue 32207: calling handle_tk_events here adds spurious
169 # queue.Empty traceback to event handling exceptions.
170 if request:
171 seq, (method, args, kwargs) = request
172 ret = method(*args, **kwargs)
173 rpc.response_queue.put((seq, ret))
174 else:

Callers

nothing calls this directly

Calls 8

methodFunction · 0.85
handle_tk_eventsFunction · 0.85
capture_warningsFunction · 0.70
exitFunction · 0.70
print_exceptionFunction · 0.70
startMethod · 0.45
getMethod · 0.45
putMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…