From 1a7d3b77fbd582336447f64d16163045812eacc6 Mon Sep 17 00:00:00 2001 From: Alexey Katsman Date: Tue, 2 Dec 2025 15:34:03 +0100 Subject: [PATCH] PY-85162 Add registry key for timeout to guess SDK (cherry picked from commit b044fee434c707575efe27bb383ef0e57747a347) IJ-MR-184472 GitOrigin-RevId: ec0c53e404f92c6b75753c8c79b6a2461c2ef461 --- python/pluginResources/intellij.python.community.impl.xml | 2 ++ .../python/sdk/add/v2/PythonAddCustomInterpreter.kt | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/python/pluginResources/intellij.python.community.impl.xml b/python/pluginResources/intellij.python.community.impl.xml index ae1dc588a8c0..55085399979a 100644 --- a/python/pluginResources/intellij.python.community.impl.xml +++ b/python/pluginResources/intellij.python.community.impl.xml @@ -693,6 +693,8 @@ + + diff --git a/python/src/com/jetbrains/python/sdk/add/v2/PythonAddCustomInterpreter.kt b/python/src/com/jetbrains/python/sdk/add/v2/PythonAddCustomInterpreter.kt index abcb70b38ca3..88ac1f04eddb 100644 --- a/python/src/com/jetbrains/python/sdk/add/v2/PythonAddCustomInterpreter.kt +++ b/python/src/com/jetbrains/python/sdk/add/v2/PythonAddCustomInterpreter.kt @@ -9,6 +9,7 @@ import com.intellij.openapi.ui.ValidationInfo import com.intellij.openapi.ui.validation.DialogValidationRequestor import com.intellij.openapi.ui.validation.WHEN_PROPERTY_CHANGED import com.intellij.openapi.ui.validation.and +import com.intellij.openapi.util.registry.RegistryManager import com.intellij.platform.ide.progress.ModalTaskOwner import com.intellij.platform.ide.progress.TaskCancellation import com.intellij.platform.ide.progress.withModalProgress @@ -36,6 +37,7 @@ import com.jetbrains.python.sdk.configuration.CreateSdkInfo import com.jetbrains.python.sdk.configuration.CreateSdkInfoWithTool import kotlinx.coroutines.* import org.jetbrains.annotations.ApiStatus.Internal +import kotlin.time.Duration import kotlin.time.Duration.Companion.seconds class ValidationInfoError(val validationInfo: ValidationInfo) : MessageError(validationInfo.message) @@ -178,7 +180,7 @@ internal class PythonAddCustomInterpreter

( } else scope.launch(Dispatchers.Default) { val createSdkInfoWithTool = withModalProgress(ModalTaskOwner.guess(), message("sdk.create.check.environments"), TaskCancellation.cancellable()) { - withTimeoutOrNull(3.seconds) { bestGuessCreateSdkInfo.await() } + withTimeoutOrNull(getGuessSdkTimeout()) { bestGuessCreateSdkInfo.await() } } ?: return@launch selectBestTool(createSdkInfoWithTool) } @@ -188,6 +190,10 @@ internal class PythonAddCustomInterpreter

( return currentSdkManager.createStatisticsInfo(PythonInterpreterCreationTargets.LOCAL_MACHINE) } + private fun getGuessSdkTimeout(): Duration = RegistryManager.getInstance().intValue("python.guess.sdk.timeout.seconds").let { i -> + (if (i > 0) i else 3).seconds + } + private fun selectBestTool(createSdkInfoWithTool: CreateSdkInfoWithTool) { val (manager, configurators) = when (createSdkInfoWithTool.createSdkInfo) { is CreateSdkInfo.WillCreateEnv -> {