code: def _send_batch(self):
          
          # We can be triggered by the LoopingCall, and have nothing to send...
          # Or, we've got SendRequest(s) to send, but are still processing the
          # previous batch...
          if (not self._batch_reqs) or self._batch_send_d:
              return
  
          # Save a local copy, and clear the global list & metrics
          requests, self._batch_reqs = self._batch_reqs, []
          self._waitingByteCount = 0
          self._waitingMsgCount = 0
  
          # Iterate over them, fetching the partition for each message batch
          d_list = []
          for req in requests:
              # For each request, we get the topic & key and use that to lookup
              # the next partition on which we should produce
              d_list.append(self._next_partition(req.topic, req.key))
          d = self._batch_send_d = Deferred()
          # Since DeferredList doesn't propagate cancel() calls to deferreds it
          # might be waiting on for a result, we need to use this structure,
          # rather than just using the DeferredList directly
          d.addCallback(lambda r: DeferredList(d_list, consumeErrors=True))
          d.addCallback(self._send_requests, requests)
          # Once we finish fully processing the current batch, clear the
          # _batch_send_d and check if any more requests piled up when we
          # were busy.
          d.addBoth(self._complete_batch_send)
          d.addBoth(self._check_send_batch)
          # Fire off the callback to start processing...
          d.callback(None)
docs: Send the waiting messages, if there are any, and we can...
  
          This is called by our LoopingCall every send_every_t interval, and
          from send_messages everytime we have enough messages to send.
          This is also called from py:method:`send_messages` via
          py:method:`_check_send_batch` if there are enough messages/bytes
          to require a send.
          Note, the send will be delayed (triggered by completion or failure of
          previous) if we are currently trying to complete the last batch send.