def restart(self): ''' (re)starts a Python IDE-server this method is complicated by SublimePythonIDE having two different debug modes, - one in which the server is started manually by the developer, in which case this developer has to set the DEBUG_PORT constant - and one case where the server is started automatically but in a verbose mode, in which it prints to its stderr, which is copied to ST3's console by an AsynchronousFileReader. For this the developer has to set SERVER_DEBUGGING to True ''' try: if DEBUG_PORT is not None: # debug mode one self.port = DEBUG_PORT self.proc = DebugProcDummy() print("started server on user-defined FIXED port %i with %s" % (self.port, self.python)) elif SERVER_DEBUGGING: # debug mode two self.port = self.get_free_port() proc_args = [ self.python, SERVER_SCRIPT, str(self.port), " --debug" ] self.proc = subprocess.Popen(proc_args, cwd=os.path.dirname(self.python), stderr=subprocess.PIPE, creationflags=CREATION_FLAGS) self.queue = Queue() self.stderr_reader = AsynchronousFileReader( "Server on port %i - STDERR" % self.port, self.proc.stderr, self.queue) self.stderr_reader.start() sublime.set_timeout_async(self.debug_consume, 1000) print("started server on port %i with %s IN DEBUG MODE" % (self.port, self.python)) else: # standard run of the server in end-user mode self.port = self.get_free_port() proc_args = [self.python, SERVER_SCRIPT, str(self.port)] self.proc = subprocess.Popen(proc_args, cwd=os.path.dirname(self.python), creationflags=CREATION_FLAGS) print("started server on port %i with %s" % (self.port, self.python)) # wait 100 ms to make sure python proc is still running for i in range(10): time.sleep(0.01) if self.proc.poll(): if SERVER_DEBUGGING: print(sys.exc_info()) raise OSError( None, "Python interpretor crashed (using path %s)" % self.python) # in any case, we also need a local client object self.proxy = xmlrpc.client.ServerProxy( 'http://%s:%i' % (self.resolve_localhost(), self.port), allow_none=True) self.set_heartbeat_timer() except OSError as e: print("error starting server:", e) print( "-----------------------------------------------------------------------------------------------" ) print( "Try to use an absolute path to your projects python interpreter. On Windows try to use forward" ) print( "slashes as in C:/Python27/python.exe or properly escape with double-backslashes" "") print( "-----------------------------------------------------------------------------------------------" ) raise e