make cython app exit correctly

This commit is contained in:
Alex Bezdieniezhnykh
2025-02-11 20:40:49 +02:00
parent 9973a16ada
commit 43cae0d03c
9 changed files with 87 additions and 65 deletions
@@ -11,6 +11,7 @@ namespace Azaion.CommonSecurity.Services;
public interface IResourceLoader
{
MemoryStream LoadFileFromPython(string fileName);
void StopPython();
}
public interface IAuthProvider
@@ -49,11 +50,11 @@ public class PythonResourceLoader : IResourceLoader, IAuthProvider
using var process = new Process();
process.StartInfo = new ProcessStartInfo
{
FileName = SecurityConstants.AzaionInferencePath,
FileName = SecurityConstants.AZAION_INFERENCE_PATH,
Arguments = $"-e {credentials.Email} -p {credentials.Password} -f {apiConfig.ResourcesFolder}",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
//UseShellExecute = false,
//RedirectStandardOutput = true,
// RedirectStandardError = true,
//CreateNoWindow = true
};
@@ -62,18 +63,10 @@ public class PythonResourceLoader : IResourceLoader, IAuthProvider
process.Start();
}
public async Task LoadFileFromApi(CancellationToken cancellationToken = default)
public void StopPython()
{
var hardwareService = new HardwareService();
var hardwareInfo = hardwareService.GetHardware();
var encryptedStream = await _api.GetResource("azaion_inference.exe", _credentials.Password, hardwareInfo, cancellationToken);
var key = Security.MakeEncryptionKey(_credentials.Email, _credentials.Password, hardwareInfo.Hash);
var stream = new MemoryStream();
await encryptedStream.DecryptTo(stream, key, cancellationToken);
stream.Seek(0, SeekOrigin.Begin);
_dealer.SendFrame(MessagePackSerializer.Serialize(new RemoteCommand(CommandType.Exit)));
_dealer?.Close();
}
public MemoryStream LoadFileFromPython(string fileName)