Promise<XDebugSession> (@NotNull RunProfileState state, @NotNull ExecutionEnvironment environment) { final PythonCommandLineState pyState = (PythonCommandLineState)state; final RunProfile profile = environment.getRunProfile(); Sdk sdk = pyState.getSdk(); PyDebugSessionFactory sessionCreator = PyDebugSessionFactory.findExtension(sdk); if (sessionCreator != null) { return AppUIExecutor.onWriteThread().submit(() -> sessionCreator.createSession(pyState, environment)); } return Promises .runAsync(() -> { try { final ServerSocket serverSocket = PythonCommandLineState.createServerSocket(); final int serverLocalPort = serverSocket.getLocalPort(); final ExecutionResult result = pyState .execute(environment.getExecutor(), createCommandLinePatchers(environment.getProject(), pyState, profile, 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); })); }