<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _do_wait(self, timeout):
 """Wait for the deferred to be completed for a period of time Raises TimeoutError if the wait times out before the future is done. Raises CancelledError if the future is cancelled before the timeout is done. """


        if self._cancelled:
            raise CancelledError()

        if not self._done:
            self._wait = True
            
            self._sigint = pyev.Signal(signal.SIGINT, self.loop, lambda watcher, events: self._cancel(), None)
            self._sigint.start()

            if timeout and timeout > 0.0:
                self._timer = pyev.Timer(timeout, 0.0, self.loop,
                                         self._clear_wait, None)
                self._timer.start()

            while self._wait and not self._done and not self._cancelled:
                self.loop.start(pyev.EVRUN_ONCE)

        if self._cancelled:
            raise CancelledError()
        elif not self._done:
            raise TimeoutError()