Feed on

if you call a shell process from python, your script will normally trundle along without pausing for that process to complete.  if you’d like the process to finish before your script continues on, use the communicate method:

proc = sub.Popen(my_job,stdout=sub.PIPE)
stdout,stderr = proc.communicate()

Bookmark and Share

if that was helpful ...

check out the other tips and tricks i've compiled on these pages. you might learn something else interesting!

3 Responses to “wait for an executed subprocess to complete in python”

  1. on 05 Dec 2009 at 3:46 pm craig

    thank you so much. i am still fairly new at python programming and was having a very hard time finding this information on google. i am sure this was due to my search query, but still, thanks a million man.

  2. on 17 Dec 2009 at 5:39 pm Charles Notley

    You could also use the wait method:

    proc = sub.Popen(my_job).wait()

  3. on 11 Dec 2011 at 3:37 am 5 mistakes

    Your blog is pretty interesting to me and your topics are very relevant. I was browsing around and came across something you might find interesting. I was guilty of 3 of them with my sites. “99% of website managers are doing these 5 mistakes”. http://bit.ly/s7O5FK You will be suprised how simple they are to fix.

Did I get this wrong? Let me know!

Trackback URI | Comments RSS