Kick off a delete command from python and not wait

Discussion in 'Python' started by loial, Jul 20, 2010.

  1. loial

    loial Guest

    I have a requirement to kick off a shell script from a python script
    without waiting for it to complete. I am not bothered about any return
    code from the script.

    What is the easiest way to do this. I have looked at popen but cannot
    see how to do it.
    loial, Jul 20, 2010
    #1
    1. Advertising

  2. loial

    Chris Rebert Guest

    On Tue, Jul 20, 2010 at 8:33 AM, loial <> wrote:
    > I have a requirement to kick off a shell script from a python script
    > without waiting for it to complete. I am not bothered about any return
    > code from the script.
    >
    > What is the easiest way to do this. I have looked at popen but cannot
    > see how to do it.


    Use the `subprocess` module.

    import subprocess
    proc = subprocess.Popen(["shell_script.sh", "arg1", "arg2"],
    stdout=subprocess.PIPE, stderr=subprcoess.PIPE)
    # lots of code here doing other stuff
    proc.wait()

    I believe you need to /eventually/ call .wait() as shown to avoid the
    child becoming a zombie process.

    Cheers,
    Chris
    --
    http://blog.rebertia.com
    Chris Rebert, Jul 20, 2010
    #2
    1. Advertising

  3. loial

    Nobody Guest

    On Tue, 20 Jul 2010 10:32:12 -0700, Chris Rebert wrote:

    > I believe you need to /eventually/ call .wait() as shown to avoid the
    > child becoming a zombie process.


    Alternatively, you can call .poll() periodically. This is similar to
    ..wait() insofar as it will "reap" the process if it has terminated, but
    unlike .wait(), .poll() won't block if the process is still running.

    On Unix, you can use os.fork(), have the child execute the command in the
    background, and have the parent wait for the child with os.wait(). The
    child will terminate as soon as it has spawned the grandchild, and the
    grandchild will be reaped automatically upon termination (so you can
    forget about it).
    Nobody, Jul 20, 2010
    #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. greg
    Replies:
    2
    Views:
    715
    Scott M.
    Aug 27, 2004
  2. Carl Johansen
    Replies:
    3
    Views:
    943
    Carl Johansen
    Jul 3, 2005
  3. rodchar

    kick off batch sproc

    rodchar, Aug 1, 2008, in forum: ASP .Net
    Replies:
    0
    Views:
    257
    rodchar
    Aug 1, 2008
  4. Sebastián_UY

    Kick Off

    Sebastián_UY, Oct 9, 2003, in forum: ASP .Net Mobile
    Replies:
    0
    Views:
    127
    Sebastián_UY
    Oct 9, 2003
  5. Carl Johansen
    Replies:
    1
    Views:
    163
    Bob Barrows [MVP]
    Jul 2, 2005
Loading...

Share This Page