5

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?

d33tah
  • 10,999
  • 13
  • 68
  • 158
Utku Zihnioglu
  • 4,714
  • 3
  • 38
  • 50

3 Answers3

2

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.

Amber
  • 507,862
  • 82
  • 626
  • 550
  • Thanks for the answer, is there another way to solve this problem with python? – Utku Zihnioglu Jan 01 '11 at 14:27
  • If your subprocesses have some means of output that your master process could monitor, they could output "I'm alive" indicators at regular intervals, and the absence of such an indicator for a significantly long period of time could be taken to mean that the subprocess has crashed. – Amber Jan 01 '11 at 15:08
2

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

Community
  • 1
  • 1
Utku Zihnioglu
  • 4,714
  • 3
  • 38
  • 50
  • 1
    similar code in python - http://stackoverflow.com/questions/5069224/handling-subprocess-crash-in-windows – n611x007 Feb 20 '13 at 14:17
0

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.

Jordan Stefanelli
  • 1,446
  • 1
  • 13
  • 13