From b313cb58dba4f84673e2f09761a6c8d0f1199b9d Mon Sep 17 00:00:00 2001 From: Cory Rivera Date: Fri, 19 Jul 2019 14:28:34 -0700 Subject: [PATCH] Check if python is running using powershell commands before doing install on Windows. (#6405) --- .../src/jupyter/jupyterServerInstallation.ts | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/extensions/notebook/src/jupyter/jupyterServerInstallation.ts b/extensions/notebook/src/jupyter/jupyterServerInstallation.ts index 862277e199..363a6658f3 100644 --- a/extensions/notebook/src/jupyter/jupyterServerInstallation.ts +++ b/extensions/notebook/src/jupyter/jupyterServerInstallation.ts @@ -277,8 +277,20 @@ export class JupyterServerInstallation { }; } - private isPythonRunning(pythonInstallPath: string): Promise { - return Promise.resolve(false); + private async isPythonRunning(installPath: string, existingPython: boolean): Promise { + 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 { - 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); }