Trace batches that stop early

A message-delivery framework supports early termination: it stops examining a batch once two records have been delivered. Its controlling method is shown below. Each method call returns normally, accept has no side effects, and there are no retries.


Python
def run_batches(self, batches):
    for batch in batches:
        delivered = 0
        for record in batch:
            if self.accept(record):
                self.deliver(record)
                delivered += 1
                if delivered == 2:
                    break


The potential accept outcomes in original record order are:

  • Batch A: false, true, false, true, true.
  • Batch B: false, false, true, false, false, true, true.
  • Batch C: true, false, true, false.

An outcome is produced only if its record is actually examined. All three batches are supplied to run_batches in the listed order.


Three batches list true and false acceptance outcomes in their original record order.


How many calls to accept occur across the complete execution? Answer in calls, as an exact whole number.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Object-Oriented Frameworks Questions: