Promise<XDebugSession> (@NotNull RunProfileState state, @NotNull final ExecutionEnvironment environment) { PythonCommandLineState pyState = (PythonCommandLineState)state; RunProfile profile = environment.getRunProfile(); return Promises .runAsync(() -> { int serverLocalPort = findAvailableSocketPort(); try { PythonDebuggerScriptTargetedCommandLineBuilder debuggerScriptCommandLineBuilder = new PythonDebuggerScriptTargetedCommandLineBuilder(environment.getProject(), pyState, profile, serverLocalPort); ExecutionResult result = pyState.execute(environment.getExecutor(), debuggerScriptCommandLineBuilder); ServerSocket serverSocket = debuggerScriptCommandLineBuilder.getServerSocketForDebugging(); if (serverSocket == null) { LOG.error("The server socket has not been created after the target environment preparation" + ", trying to fallback and create the server socket on the loopback address"); serverSocket = createServerSocketOnLoopbackAddress(serverLocalPort); } return Pair.create(serverSocket, result); } catch (ExecutionException err) { throw new RuntimeException(err.getMessage(), err); } }) .thenAsync(pair -> AppUIExecutor.onUiThread().submit(() -> { ServerSocket serverSocket = pair.getFirst(); ExecutionResult result = pair.getSecond(); return createXDebugSession(environment, pyState, serverSocket, result); })); }