def _flush_batch(self, batch): self.on_before_batch_flush(batch) try: batch.flush() finally: self.on_after_batch_flush(batch) return 0