为了账号安全,请及时绑定邮箱和手机立即绑定

如果单独运行python就没有问题,这是为什么啊?反之就不可以

如果单独运行python就没有问题,这是为什么啊?反之就不可以

C#
慕森王 2023-04-17 21:17:42
我在一个winform的c#程序里通过process调用python程序,这个python程序里有多线程。现在问题是我调用的python程序可以跑,但是跑一会就不能运行了,但是我如果单独运行python就没有问题,这是为什么。ic void RunPythonScript(string path, string args = "")         {             path = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "script\\" + path;                          p.StartInfo.FileName = "python.exe";            string sArguments = "\"" + path + "\"";             if (args.Length > 0)             {                 sArguments += " " + args;             }             //p.StartInfo.WorkingDirectory = "D:\\";             p.StartInfo.Arguments = sArguments;             p.StartInfo.UseShellExecute = false;             p.StartInfo.RedirectStandardOutput = true;             p.StartInfo.RedirectStandardInput = true;             p.StartInfo.RedirectStandardError = true;             p.StartInfo.CreateNoWindow = true;             p.Start();             //p.CloseMainWindow();             //p.WaitForExit();         }`
查看完整描述

1 回答

?
jeck猫

TA贡献1909条经验 获得超7个赞

把下面的这行代码取消注释就可以了。前提你这个操作是在主线程之外。不然会阻塞。

//p.WaitForExit();


查看完整回答
反对 回复 2023-04-20
  • 1 回答
  • 0 关注
  • 89 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信