Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Kick off a delete command from python and not wait

Reply
Thread Tools

Kick off a delete command from python and not wait

 
 
loial
Guest
Posts: n/a
 
      07-20-2010
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.



 
Reply With Quote
 
 
 
 
Chris Rebert
Guest
Posts: n/a
 
      07-20-2010
On Tue, Jul 20, 2010 at 8:33 AM, loial <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Nobody
Guest
Posts: n/a
 
      07-20-2010
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).


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
kick off batch sproc rodchar ASP .Net 0 08-01-2008 05:40 PM
aspx page to kick off async background task and then end Carl Johansen ASP .Net 3 07-03-2005 01:06 PM
aspx page to kick off async background task and then end Carl Johansen ASP General 1 07-02-2005 08:07 PM
web form needs to kick off console app ??? greg ASP .Net 2 08-27-2004 03:53 AM
Kick Off Sebastián_UY ASP .Net Mobile 0 10-09-2003 02:16 PM



Advertisments