diff --git a/playhouse/sqliteq.py b/playhouse/sqliteq.py index 1b156496e..7920cd9ef 100644 --- a/playhouse/sqliteq.py +++ b/playhouse/sqliteq.py @@ -281,8 +281,18 @@ def stop(self): with self._qlock: if self._is_stopped: return False + self._write_queue.put((SHUTDOWN, None)) self._writer.join() + + # Empty queue of any remaining tasks. + while not self._write_queue.empty(): + op, obj = self._write_queue.get() + if op == PAUSE or op == UNPAUSE: + obj.set() + elif op == QUERY: + obj.set_result(None, ShutdownException()) + self._is_stopped = True return True