I have an asp.net
backend app that needs to trigger a large python script through CLI with StartProcessInfo()
.
Code that launches python with arguments using Process.Start()
:
public void Func(args){
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = @"C:\path\to\python.exe";
string script = @"script.py";
psi.WorkingDirectory = @"C:\path\to\dir";
psi.Arguments = $"{script} {args}";
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
string errors = string.Empty;
string results = string.Empty;
Debug.WriteLine(psi.Arguments);
using (Process process = Process.Start(psi))
{
results = process.StandardOutput.ReadToEnd();
errors = process.StandardError.ReadToEnd();
process.WaitForExit();
process.Close();
}
Debug.WriteLine(results);
Debug.WriteLine(errors);
}
my problem is, when the script is ran by Process.Start()
it's memory usage rises to 3-4 GB of ram, then falls down rapidly to 2.1-2.4 GB of ram and freezes even though i have 8 GB of free memory.
and when i launch the script manually it runs perfectly fine with 5.5 GB of ram used.
is there a way to trigger the python script with arguments without having it memory constrained to 2 GB?
I'm using .net
x64 version 4.7.2 on win10x64 with if it helps.
EDIT: This question might be considered to be a duplicate as there are already other questions about limitations of C# application. But, this question is focused to executing other application (python.exe
) and avoiding inheritance of those limitations between original ASP.NET app and other python.exe
app. This scenario is not mentioned in linked-duplicate question and might have different solution/answer.