Running programs under a python program...

Discussion in 'Python' started by samslists@gmail.com, May 21, 2008.

  1. Guest

    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!
     
    , May 21, 2008
    #1
    1. Advertising

  2. inhahe Guest

    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

    <> wrote in message
    news:...
    > 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!
     
    inhahe, May 21, 2008
    #2
    1. Advertising

  3. <> wrote:
    > 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-
     
    Matthew Woodcraft, May 21, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hshdude
    Replies:
    12
    Views:
    1,108
    Dimitri Maziuk
    Nov 4, 2004
  2. bronby
    Replies:
    1
    Views:
    667
    Andrew Thompson
    Jul 15, 2005
  3. Replies:
    12
    Views:
    1,701
    Dave Thompson
    Jan 10, 2005
  4. Coca
    Replies:
    7
    Views:
    775
    Aidan Grey
    Aug 24, 2004
  5. lone_eagle
    Replies:
    3
    Views:
    668
    psykeedelik
    May 26, 2009
Loading...

Share This Page