Running programs under a python program...

S

samslists

So I have a python program that runs a bunch of other programs....it
then loops forever, occasionally executing other programs.

To run each of these programs my python code executes:
subprocess.Popen(command_line, shell=True, stdout=fd,
stderr=subprocess.STDOUT)

where command_line is an appropriate command line. :)

Now my problem is when I abort this program it kills off all the child
processes I've started. In this case I don't want that. How can I
stop the child processes from dieing when I kill off the parent?

Thanks!
 
I

inhahe

maybe you could instead of killing the program stop the loop that starts
new processes and start one that runs until the last process ends?

also, if you killed the program but stdout was still set to fd and stderr
was still set to subprocesses.STDOUT, what would happen when those two
objects disappeared? wouldn't the processes crash or something?

i dunno much about this though, maybe there's some way
 
M

Matthew Woodcraft

So I have a python program that runs a bunch of other programs....it
then loops forever, occasionally executing other programs.

To run each of these programs my python code executes:
subprocess.Popen(command_line, shell=True, stdout=fd,
stderr=subprocess.STDOUT)

where command_line is an appropriate command line. :)

Now my problem is when I abort this program it kills off all the child
processes I've started. In this case I don't want that. How can I
stop the child processes from dieing when I kill off the parent?

It depends on why the children are dying.

From what you say, it seems likely that they're trying to write to
their standard output, and exiting because that's a pipe that is now
closed.

If that's the case, it's probably best to start by deciding where you
want that output to go when the parent process has ended. Perhaps you
can just send it all to a log file in the first place.

-M-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top