From f9a5f8ab3d1009bcb64896529f9622780308d3dc Mon Sep 17 00:00:00 2001 From: Ionite Date: Tue, 12 Sep 2023 17:06:10 -0400 Subject: [PATCH] Add logging of pip update in updates --- StabilityMatrix.Core/Python/PyVenvRunner.cs | 34 ++++++++++++--------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/StabilityMatrix.Core/Python/PyVenvRunner.cs b/StabilityMatrix.Core/Python/PyVenvRunner.cs index b0b6245b..2a260705 100644 --- a/StabilityMatrix.Core/Python/PyVenvRunner.cs +++ b/StabilityMatrix.Core/Python/PyVenvRunner.cs @@ -201,17 +201,14 @@ public class PyVenvRunner : IDisposable, IAsyncDisposable // Record output for errors var output = new StringBuilder(); - var outputAction = - outputDataReceived == null - ? null - : new Action(s => - { - Logger.Debug($"Pip output: {s.Text}"); - // Record to output - output.Append(s.Text); - // Forward to callback - outputDataReceived(s); - }); + var outputAction = new Action(s => + { + Logger.Debug($"Pip output: {s.Text}"); + // Record to output + output.Append(s.Text); + // Forward to callback + outputDataReceived?.Invoke(s); + }); SetPyvenvCfg(PyRunner.PythonDir); RunDetached($"-m pip install {args}", outputAction); @@ -427,9 +424,18 @@ public class PyVenvRunner : IDisposable, IAsyncDisposable if (Process is { HasExited: false }) { Process.Kill(); - await Process - .WaitForExitAsync(new CancellationTokenSource(1000).Token) - .ConfigureAwait(false); + try + { + await Process + .WaitForExitAsync(new CancellationTokenSource(1000).Token) + .ConfigureAwait(false); + } + catch (OperationCanceledException e) + { + Logger.Error(e, "Venv Process did not exit in time in DisposeAsync"); + + Process.CancelStreamReaders(); + } } Process = null;