code: def _stop_thread(self):
          
          self._stopping_event.set()
          queue_content = []
          try:  # give the enqueueing thread chance to put a batch to the queue and check the stopping event
              while True:
                  queue_content.append(self._queue.get_nowait())
          except Empty:
              pass
          self._enqueueing_thread.join()
          try:
              queue_content.append(self._queue.get_nowait())  # collect the very last item
          except Empty:
              pass
          self._queue = Queue(max(len(queue_content), self._buffer_size))  # queue content may be bigger than queue size
          for batch in queue_content:
              self._queue.put(batch)
docs: Stop the enqueueing thread. Keep the queue content and stream state.