class_docstr: The background thread that handles the sending of produce requests to the
  Kafka cluster. This thread makes metadata requests to renew its view of the
  cluster and then sends produce requests to the appropriate nodes.
docstr: The main run loop for the sender thread.
code: def run(self):
      """The main run loop for the sender thread."""
      log.debug("Starting Kafka producer I/O thread.")
  
      # main loop, runs until close is called
      while self._running:
          try:
              self.run_once()
          except Exception:
              log.exception(
                  "Uncaught error in kafka producer I/O thread"
              )
  
      log.debug(
          "Beginning shutdown of Kafka producer I/O thread, sending"
          " remaining records."
      )
  
      # okay we stopped accepting requests but there may still be
      # requests in the accumulator or waiting for acknowledgment,
      # wait until these are completed.
      while not self._force_close and (
          self._accumulator.has_unsent()
          or self._client.in_flight_request_count() > 0
      ):
          try:
              self.run_once()
          except Exception:
              log.exception(
                  "Uncaught error in kafka producer I/O thread"
              )
  
      if self._force_close:
          # We need to fail all the incomplete batches and wake up the
          # threads waiting on the futures.
          self._accumulator.abort_incomplete_batches()
  
      try:
          self._client.close()
      except Exception:
          log.exception("Failed to close network client")
  
      log.debug("Shutdown of Kafka producer I/O thread has completed.")
  
imports: from __future__ import absolute_import, division
  import collections
  import copy
  import logging
  import threading
  import time
  from kafka.vendor import six
  from kafka import errors
  from kafka.metrics.measurable import AnonMeasurable
  from kafka.metrics.stats import Avg, Max, Rate
  from kafka.protocol.produce import ProduceRequest
  from kafka.structs import TopicPartition
  from kafka.version import __version__
label_desc: Use image node_id 2 for calling the Sender obj's underlying member method code with example usage: obj.run() without return types