Check if python is running using powershell commands before doing install on Windows. (#6405)

This commit is contained in:
Cory Rivera
2019-07-19 14:28:34 -07:00
committed by GitHub
parent 62c40e4de5
commit b313cb58db

View File

@@ -277,8 +277,20 @@ export class JupyterServerInstallation {
};
}
private isPythonRunning(pythonInstallPath: string): Promise<boolean> {
return Promise.resolve(false);
private async isPythonRunning(installPath: string, existingPython: boolean): Promise<boolean> {
if (process.platform === constants.winPlatform) {
let pythonExe = JupyterServerInstallation.getPythonExePath(installPath, existingPython);
let cmd = `powershell.exe -NoProfile -Command "& {Get-Process python | Where-Object {$_.Path -eq '${pythonExe}'}}"`;
let cmdResult: string;
try {
cmdResult = await this.executeBufferedCommand(cmd);
} catch (err) {
return false;
}
return cmdResult !== undefined && cmdResult.length > 0;
} else {
return false;
}
}
/**
@@ -288,7 +300,13 @@ export class JupyterServerInstallation {
* The previous path (or the default) is used if a new path is not specified.
*/
public async startInstallProcess(forceInstall: boolean, installSettings?: { installPath: string, existingPython: boolean }): Promise<void> {
let isPythonRunning = await this.isPythonRunning(installSettings ? installSettings.installPath : this._pythonInstallationPath);
let isPythonRunning: boolean;
if (installSettings) {
isPythonRunning = await this.isPythonRunning(installSettings.installPath, installSettings.existingPython);
} else {
isPythonRunning = await this.isPythonRunning(this._pythonInstallationPath, this._usingExistingPython);
}
if (isPythonRunning) {
return Promise.reject(msgPythonRunningError);
}