Skip to content

Commit 85281a4

Browse files
committed
Add timeout to python extension search
Have only seen this happen once, so not merging into main yet unless it appears to be an actual issue
1 parent 3e26da6 commit 85281a4

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/utils/pythonHelper.mts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,24 @@ export default async function findPython(): Promise<string | undefined> {
7878
}
7979

8080
// Check python extension for any python environments with version >= 3.9
81-
pythonPath = await findPythonInPythonExtension();
81+
const awaitFind = findPythonInPythonExtension();
82+
// Timeout after 30s, as it can stall if there is no python available
83+
const onTimeout = new Promise<string>((resolve) => {
84+
setTimeout(resolve, 30000, "timeout");
85+
});
86+
87+
await Promise.race([awaitFind, onTimeout]).then((value) => {
88+
if (value === "timeout") {
89+
Logger.warn(
90+
LoggerSource.pythonHelper,
91+
"Python Extension search timed out - attempting download instead"
92+
);
93+
pythonPath = undefined;
94+
} else {
95+
pythonPath = value;
96+
}
97+
});
98+
8299
if (pythonPath) {
83100
await Settings.getInstance()?.updateGlobal(
84101
SettingsKey.python3Path,

0 commit comments

Comments
 (0)