[Tutor] os.waitpid non spawned pid

John [H2O] washakie at gmail.com
Fri Jun 20 20:37:04 CEST 2008


Hello, I would like to write a script that would have a command line option
of a pid# (known ahead of time). Then I want my script to wait to execute
until the pid is finished. How do I accomplish this?

I tried the following:
#!/usr/bin/env python

import os
import sys

def run_cmd(cmd):
   """RUN A BASH CMD"""
   import subprocess as sub
   p = sub.Popen( ['/bin/bash' , '-c' , cmd ],
                 stdout = sub.PIPE , stderr = sub.STDOUT )
   output = p.stdout.read()
   return output

r=os.waitpid(sys.argv[1],0);

cmd = 'echo "Now %s has finished " ' %r

run_cmd(cmd)

But I get the following:

-bash-3.1$ ./waitpid.py 10132
Traceback (most recent call last):
  File "./waitpid.py", line 14, in ?
    r=os.waitpid(int(sys.argv[1]),0);
OSError: [Errno 10] No child processes


-- 
View this message in context: http://www.nabble.com/os.waitpid-non-spawned-pid-tp18035187p18035187.html
Sent from the Python - tutor mailing list archive at Nabble.com.



More information about the Tutor mailing list