| 406 | |
| 407 | |
| 408 | class ModifiedInterpreter(InteractiveInterpreter): |
| 409 | |
| 410 | def __init__(self, tkconsole): |
| 411 | self.tkconsole = tkconsole |
| 412 | locals = sys.modules['__main__'].__dict__ |
| 413 | InteractiveInterpreter.__init__(self, locals=locals) |
| 414 | self.restarting = False |
| 415 | self.subprocess_arglist = None |
| 416 | self.port = PORT |
| 417 | self.original_compiler_flags = self.compile.compiler.flags |
| 418 | |
| 419 | _afterid = None |
| 420 | rpcclt = None |
| 421 | rpcsubproc = None |
| 422 | |
| 423 | def spawn_subprocess(self): |
| 424 | if self.subprocess_arglist is None: |
| 425 | self.subprocess_arglist = self.build_subprocess_arglist() |
| 426 | # gh-127060: Disable traceback colors |
| 427 | env = dict(os.environ, TERM='dumb') |
| 428 | self.rpcsubproc = subprocess.Popen(self.subprocess_arglist, env=env) |
| 429 | |
| 430 | def build_subprocess_arglist(self): |
| 431 | assert (self.port!=0), ( |
| 432 | "Socket should have been assigned a port number.") |
| 433 | w = ['-W' + s for s in sys.warnoptions] |
| 434 | # Maybe IDLE is installed and is being accessed via sys.path, |
| 435 | # or maybe it's not installed and the idle.py script is being |
| 436 | # run from the IDLE source directory. |
| 437 | del_exitf = idleConf.GetOption('main', 'General', 'delete-exitfunc', |
| 438 | default=False, type='bool') |
| 439 | command = f"__import__('idlelib.run').run.main({del_exitf!r})" |
| 440 | return [sys.executable] + w + ["-c", command, str(self.port)] |
| 441 | |
| 442 | def start_subprocess(self): |
| 443 | addr = (HOST, self.port) |
| 444 | # GUI makes several attempts to acquire socket, listens for connection |
| 445 | for i in range(3): |
| 446 | time.sleep(i) |
| 447 | try: |
| 448 | self.rpcclt = MyRPCClient(addr) |
| 449 | break |
| 450 | except OSError: |
| 451 | pass |
| 452 | else: |
| 453 | self.display_port_binding_error() |
| 454 | return None |
| 455 | # if PORT was 0, system will assign an 'ephemeral' port. Find it out: |
| 456 | self.port = self.rpcclt.listening_sock.getsockname()[1] |
| 457 | # if PORT was not 0, probably working with a remote execution server |
| 458 | if PORT != 0: |
| 459 | # To allow reconnection within the 2MSL wait (cf. Stevens TCP |
| 460 | # V1, 18.6), set SO_REUSEADDR. Note that this can be problematic |
| 461 | # on Windows since the implementation allows two active sockets on |
| 462 | # the same address! |
| 463 | self.rpcclt.listening_sock.setsockopt(socket.SOL_SOCKET, |
| 464 | socket.SO_REUSEADDR, 1) |
| 465 | self.spawn_subprocess() |
no outgoing calls
no test coverage detected
searching dependent graphs…