'Signals for the playback to stop and ends all open notes.
Args:
block: If true, blocks until thread terminates.'

def stop(self, block=True):

    with self._lock:
        if (not self._stop_signal.is_set()):
            self._stop_signal.set()
            self._allow_updates = False
            self._message_queue.clear()
            for note in self._open_notes:
                self._message_queue.append(mido.Message(type='note_off', note=note, time=time.time()))
            self._update_cv.notify()
    if block:
        self.join()
