'Wait for the started process to complete.
"timeout" is a floating point number of seconds after
which to timeout.  Default is None, which is to never timeout.
If the wait time\'s out it will raise a ProcessError. Otherwise it
will return the child\'s exit value. Note that in the case of a timeout,
the process is still running. Use kill() to forcibly stop the process.'

def wait(self, timeout=None):

    if ((timeout is None) or (timeout < 0)):
        try:
            return Popen.wait(self)
        except OSError as ex:
            if (ex.errno != 10):
                raise
            return self.returncode
    time_now = time.time()
    time_end = (time_now + timeout)
    time_wait_values = [1.0, 0.5, 0.2, 0.1]
    while (time_now < time_end):
        result = self.poll()
        if (result is not None):
            return result
        self.__hasTerminated.acquire()
        if time_wait_values:
            wait_period = time_wait_values.pop()
        self.__hasTerminated.wait(wait_period)
        self.__hasTerminated.release()
        time_now = time.time()
    result = self.poll()
    if (result is not None):
        return result
    raise ProcessError(('Process    timeout:    waited    %d    seconds,    process    not    yet    finished.' % (timeout,)), WAIT_TIMEOUT)
