Only check if python is running before trying to overwrite an existing installation. (#10383)

This commit is contained in:
Cory Rivera
2020-05-14 11:37:06 -07:00
committed by GitHub
parent 3212b06d49
commit d3e1675fc5

View File

@@ -336,10 +336,9 @@ export class JupyterServerInstallation implements IJupyterServerInstallation {
}; };
} }
private async isPythonRunning(installPath: string, existingPython: boolean): Promise<boolean> { private async isPythonRunning(pythonExePath: string): Promise<boolean> {
if (process.platform === constants.winPlatform) { if (process.platform === constants.winPlatform) {
let pythonExe = JupyterServerInstallation.getPythonExePath(installPath, existingPython); let cmd = `powershell.exe -NoProfile -Command "& {Get-Process python | Where-Object {$_.Path -eq '${pythonExePath}'}}"`;
let cmd = `powershell.exe -NoProfile -Command "& {Get-Process python | Where-Object {$_.Path -eq '${pythonExe}'}}"`;
let cmdResult: string; let cmdResult: string;
try { try {
cmdResult = await this.executeBufferedCommand(cmd); cmdResult = await this.executeBufferedCommand(cmd);
@@ -347,9 +346,9 @@ export class JupyterServerInstallation implements IJupyterServerInstallation {
return false; return false;
} }
return cmdResult !== undefined && cmdResult.length > 0; return cmdResult !== undefined && cmdResult.length > 0;
} else {
return false;
} }
return false;
} }
/** /**
@@ -359,15 +358,22 @@ export class JupyterServerInstallation implements IJupyterServerInstallation {
* The previous python path (or the default) is used if a new path is not specified. * The previous python path (or the default) is used if a new path is not specified.
*/ */
public async startInstallProcess(forceInstall: boolean, installSettings?: PythonInstallSettings): Promise<void> { public async startInstallProcess(forceInstall: boolean, installSettings?: PythonInstallSettings): Promise<void> {
let isPythonRunning: boolean; if (!installSettings) {
if (installSettings) { installSettings = {
isPythonRunning = await this.isPythonRunning(installSettings.installPath, installSettings.existingPython); installPath: this._pythonInstallationPath,
} else { existingPython: this._usingExistingPython
isPythonRunning = await this.isPythonRunning(this._pythonInstallationPath, this._usingExistingPython); };
} }
if (isPythonRunning) { // Check if Python is running before attempting to overwrite the installation.
return Promise.reject(msgPythonRunningError); // This step is skipped when using an existing installation, since we only add
// extra packages in that case and don't modify the install itself.
if (!installSettings.existingPython) {
let pythonExePath = JupyterServerInstallation.getPythonExePath(installSettings.installPath, false);
let isPythonRunning = await this.isPythonRunning(pythonExePath);
if (isPythonRunning) {
return Promise.reject(msgPythonRunningError);
}
} }
if (this._installInProgress) { if (this._installInProgress) {
@@ -378,10 +384,8 @@ export class JupyterServerInstallation implements IJupyterServerInstallation {
this._installInProgress = true; this._installInProgress = true;
this._installCompletion = new Deferred<void>(); this._installCompletion = new Deferred<void>();
if (installSettings) { this._pythonInstallationPath = installSettings.installPath;
this._pythonInstallationPath = installSettings.installPath; this._usingExistingPython = installSettings.existingPython;
this._usingExistingPython = installSettings.existingPython;
}
await this.configurePackagePaths(); await this.configurePackagePaths();
let updateConfig = async () => { let updateConfig = async () => {
@@ -397,7 +401,7 @@ export class JupyterServerInstallation implements IJupyterServerInstallation {
description: msgTaskName, description: msgTaskName,
isCancelable: false, isCancelable: false,
operation: op => { operation: op => {
this.installDependencies(op, forceInstall, installSettings?.specificPackages) this.installDependencies(op, forceInstall, installSettings.specificPackages)
.then(async () => { .then(async () => {
await updateConfig(); await updateConfig();
this._installCompletion.resolve(); this._installCompletion.resolve();