如何确定程序是否因子进程而崩溃?

发布于 2024-10-10 02:37:18 字数 305 浏览 0 评论 0原文

我的应用程序创建子流程。通常,这些进程运行和终止不会出现任何问题。然而,有时它们会崩溃。

我目前正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一抹微笑 2024-10-17 02:37:18

当调试器打开时,进程尚未完成 - 并且 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 via subprocess.

花想c 2024-10-17 02:37:18

我找到了解决这个问题的方法。我使用了另一个问题中给出的解决方案 “应用程序错误”对话框可以吗被禁用?

I found a workaround for this problem. I used the solution given in another question Can the "Application Error" dialog box be disabled?

烟酉 2024-10-17 02:37:18

注意事项:

子进程返回代码的 subprocess.check_output()
psutil 用于进程和儿童分析(以及更多)
线程库,一旦您决定如何处理崩溃,也可以监视脚本中的这些子状态(如果需要)

import psutil
myprocess = psutil.Process(process_id) # you can find your process id in various ways of your choosing
for child in myprocess.children():
    print("Status of child process is: {0}".format(child.status()))

您还可以使用线程库将子进程加载到单独的线程中,然后执行上述 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

import psutil
myprocess = psutil.Process(process_id) # you can find your process id in various ways of your choosing
for child in myprocess.children():
    print("Status of child process is: {0}".format(child.status()))

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文