From 9e07503d11442bfafb84108d0f0e339eb29c040f Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Mon, 23 Oct 2023 11:28:34 -0700 Subject: [PATCH] Use taskkill to kill processes on Windows (#22286) For https://github.com/microsoft/vscode-python/issues/22285 --- src/client/common/process/rawProcessApis.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/client/common/process/rawProcessApis.ts b/src/client/common/process/rawProcessApis.ts index 23c2f3253bb1..7d7a66cae884 100644 --- a/src/client/common/process/rawProcessApis.ts +++ b/src/client/common/process/rawProcessApis.ts @@ -73,7 +73,11 @@ export function shellExec( const disposable: IDisposable = { dispose: () => { if (!proc.killed) { - proc.kill(); + if (proc.pid) { + killPid(proc.pid); + } else { + proc.kill(); + } } }, }; @@ -101,7 +105,11 @@ export function plainExec( const disposable: IDisposable = { dispose: () => { if (!proc.killed) { - proc.kill(); + if (proc.pid) { + killPid(proc.pid); + } else { + proc.kill(); + } } }, }; @@ -219,7 +227,11 @@ export function execObservable( internalDisposables.push( options.token.onCancellationRequested(() => { if (!procExited && !proc.killed) { - proc.kill(); + if (proc.pid) { + killPid(proc.pid); + } else { + proc.kill(); + } procExited = true; } }), @@ -279,6 +291,6 @@ export function killPid(pid: number): void { process.kill(pid); } } catch { - // Ignore. + traceVerbose('Unable to kill process with pid', pid); } }