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. Advertisements

  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. Advertisements

  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. Advertisements

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. Paul Faulstich
    Replies:
    1
    Views:
    1,269
    Amy G
    Jan 10, 2004
  2. hshdude
    Replies:
    12
    Views:
    1,343
    Dimitri Maziuk
    Nov 4, 2004
  3. bronby
    Replies:
    1
    Views:
    896
    Andrew Thompson
    Jul 15, 2005
  4. Bob=Moore
    Replies:
    10
    Views:
    3,103
  5. Jorgen Grahn
    Replies:
    3
    Views:
    796
    Jorgen Grahn
    Feb 18, 2004
  6. M.N.A.Smadi

    running programs from within python

    M.N.A.Smadi, Mar 9, 2005, in forum: Python
    Replies:
    0
    Views:
    384
    M.N.A.Smadi
    Mar 9, 2005
  7. lone_eagle
    Replies:
    3
    Views:
    838
    psykeedelik
    May 26, 2009
  8. zigzagdna
    Replies:
    3
    Views:
    459
    John B. Matthews
    Mar 20, 2011
Loading...