'Wait for the process to finish. When timeout is provided, process is
safely destroyed after timeout.
:param timeout: Acceptable timeout
:return: results of this command'

def wait_for(self, timeout=None):

    if (timeout is None):
        self.sp.wait()
    if (timeout > 0):
        start_time = time.time()
        while ((time.time() - start_time) < timeout):
            self.result.exit_status = self.sp.poll()
            if (self.result.exit_status is not None):
                break
    else:
        timeout = 1
    self.kill_func()
    stop_time = (time.time() + timeout)
    while (time.time() < stop_time):
        self.result.exit_status = self.sp.poll()
        if (self.result.exit_status is not None):
            break
    else:
        try:
            os.kill(self.sp.pid, signal.SIGKILL)
        except OSError:
            pass
    try:
        (_, self.result.exit_status) = os.waitpid(self.sp.pid, 0)
    except OSError:
        self.result.exit_status = self.sp.poll()
    self.result.duration = (time.time() - self.start_time)
    assert (self.result.exit_status is not None)
    self.stdout_thread.join(1)
    self.stderr_thread.join(1)
    assert (not self.stdout_thread.isAlive())
    assert (not self.stderr_thread.isAlive())
    super(AsyncJob, self).cleanup()
    return self.result
