2

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.

Tatranskymedved
  • 4,194
  • 3
  • 21
  • 47
GOX
  • 51
  • 3

1 Answers1

0

We solved the problem by making a script attached to C# which acts as an interface between ASP.NET and the detached process(high memory usage). Thus, bypassing memory limitations or rather, the whole ASP.NET.

  • Welcome to Stackoverflow. Make sure you've read the guidelines for posting questions and answers. As a rule of thumbs, post code and clear descriptions of solutions. Do not assume that the person that first asked the question knows what you are talking about. – Serge de Gosson de Varennes Nov 19 '20 at 12:17