def has_undrained(self):
        """Check whether there are any batches which haven't been drained"""
        for tp in list(self._batches.keys()):
            with self._tp_lock(tp):
                dq = self._batches[tp]
                if len(dq):
                    return True
        return False
Check whether there are any batches which haven't been drained
kafka/producer/record_accumulator.py