如何确定程序是否因子进程而崩溃?
我的应用程序创建子流程。通常,这些进程运行和终止不会出现任何问题。然而,有时它们会崩溃。
我目前正在使用 python 子进程模块 来创建这些子进程。我通过调用 Popen.poll() 方法来检查子进程是否崩溃。不幸的是,由于我的调试器在崩溃时被激活,轮询不会返回预期的输出。
我希望能够看到调试窗口(而不是终止它),并且仍然能够检测 python 代码中的进程是否崩溃。
有办法做到这一点吗?
My application creates subprocesses. Usually, these processeses run and terminate without any problems. However, sometimes, they crash.
I am currently using the python subprocess module to create these subprocesses. I check if a subprocess crashed by invoking the Popen.poll()
method. Unfortunately, since my debugger is activated at the time of a crash, polling doesn't return the expected output.
I'd like to be able to see the debugging window(not terminate it) and still be able to detect if a process is crashed in the python code.
Is there a way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当调试器打开时,进程尚未完成 - 并且
subprocess
只知道进程是否正在运行或已完成。所以不,没有办法通过子进程
来做到这一点。When your debugger opens, the process isn't finished yet - and
subprocess
only knows if a process is running or finished. So no, there is not a way to do this viasubprocess
.我找到了解决这个问题的方法。我使用了另一个问题中给出的解决方案 “应用程序错误”对话框可以吗被禁用?
I found a workaround for this problem. I used the solution given in another question Can the "Application Error" dialog box be disabled?
注意事项:
子进程返回代码的 subprocess.check_output()
psutil 用于进程和儿童分析(以及更多)
线程库,一旦您决定如何处理崩溃,也可以监视脚本中的这些子状态(如果需要)
您还可以使用线程库将子进程加载到单独的线程中,然后执行上述 psutil与您的其他过程同时进行分析。
如果您发现更多内容,请告诉我,我找到这篇文章并非巧合。
Items of consideration:
subprocess.check_output() for your child processes return codes
psutil for process & child analysis (and much more)
threading library, to monitor these child states in your script as well once you've decided how you want to handle the crashing, if desired
You can also use the threading library to load your subprocess into a separate thread, and then perform the above psutil analyses concurrently with your other process.
If you find more, let me know, it's no coincidence I've found this post.