'Stop the listener.
This asks the thread to terminate, and then waits for it to do so.
Note that if you don\'t call this before your application exits, there
may be some records still left on the queue, which won\'t be processed.'

def stop(self):

    self._stop.set()
    self.enqueue_sentinel()
    self._thread.join()
    self._thread = None
