Python 通过Process.Start()启动的进程的内存限制为2 GB

Python 通过Process.Start()启动的进程的内存限制为2 GB,python,c#,asp.net,.net,visual-studio,Python,C#,Asp.net,.net,Visual Studio,我有一个asp.net后端应用程序,需要通过CLI使用StartProcessInfo()触发一个大型python脚本 使用Process.Start()启动带有参数的python的代码: 我的问题是,当脚本通过Process.Start()运行时,它的内存使用率上升到3-4 GB的ram,然后迅速下降到2.1-2.4 GB的ram,即使我有8 GB的可用内存,也会冻结 当我手动启动脚本时,它运行得非常好,使用了5.5 GB的ram 有没有一种方法可以在不将python脚本的内存限制为2GB的情

我有一个
asp.net
后端应用程序,需要通过CLI使用
StartProcessInfo()
触发一个大型python脚本

使用Process.Start()启动带有参数的python的代码:

我的问题是,当脚本通过
Process.Start()
运行时,它的内存使用率上升到3-4 GB的ram,然后迅速下降到2.1-2.4 GB的ram,即使我有8 GB的可用内存,也会冻结

当我手动启动脚本时,它运行得非常好,使用了5.5 GB的ram

有没有一种方法可以在不将python脚本的内存限制为2GB的情况下触发带有参数的python脚本

我正在win10x64上使用
.net
x64 4.7.2版,如果有帮助的话



编辑:这个问题可能被认为是重复的,因为已经有关于C#应用程序限制的其他问题。但是,这个问题的重点是执行其他应用程序(
python.exe
),并避免在原始ASP.NET应用程序和其他
python.exe
应用程序之间继承这些限制。链接重复问题中未提及此场景,可能有不同的解决方案/答案。

我们通过将脚本附加到C#解决了此问题,C#充当ASP.NET和分离进程之间的接口(内存使用率高)。因此,绕过内存限制,或者更确切地说,绕过整个ASP.NET。

您在x64机器上运行,但您的代码是否编译到x64程序集?@WaiHaLee是的,x64程序集欢迎使用Stackoverflow。确保你已经阅读了发布问题和答案的指南。根据经验,发布代码并清楚描述解决方案。不要以为第一个问问题的人知道你在说什么。
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);
}