'Returns a `.Future` which resolves when the process exits.
Usage::
ret = yield proc.wait_for_exit()
This is a coroutine-friendly alternative to `set_exit_callback`
(and a replacement for the blocking `subprocess.Popen.wait`).
By default, raises `subprocess.CalledProcessError` if the process
has a non-zero exit status. Use ``wait_for_exit(raise_error=False)``
to suppress this behavior and return the exit status without raising.
.. versionadded:: 4.2'

def wait_for_exit(self, raise_error=True):

    future = Future()
    def callback(ret):
        if ((ret != 0) and raise_error):
            future.set_exception(CalledProcessError(ret, None))
        else:
            future.set_result(ret)
    self.set_exit_callback(callback)
    return future
