'Captures incoming messages until stop time or signal received.'

def run(self):

    while True:
        timeout = None
        stop_time = self._stop_time
        if (stop_time is not None):
            timeout = (stop_time - time.time())
            if (timeout <= 0):
                break
        try:
            msg = self._receive_queue.get(block=True, timeout=timeout)
        except Queue.Empty:
            continue
        if (msg is MidiCaptor._WAKE_MESSAGE):
            continue
        if (msg.time <= self._start_time):
            continue
        if (self._stop_regex.match(str(msg)) is not None):
            break
        with self._lock:
            msg_str = str(msg)
            for (regex, queue) in self._iter_signals:
                if (regex.match(msg_str) is not None):
                    queue.put(msg.copy())
        self._capture_message(msg)
    stop_time = self._stop_time
    end_time = (stop_time if (stop_time is not None) else msg.time)
    with self._lock:
        self._captured_sequence = self.captured_sequence(end_time)
        for (regex, queue) in self._iter_signals:
            queue.put(MidiCaptor._WAKE_MESSAGE)
