'This is borrowed from subprocess.Popen.'

def wait(self):

    if (self.returncode is None):
        (pid, sts) = os.waitpid(self.pid, 0)
        self._handle_exitstatus(sts)
    return self.returncode
