D02 · PREDICT · OPERATE · EXPLAIN YOUR CHOICE
Queue Lab: Process Jobs in Order and Inspect Ring Buffers
One failed check prevents later documents from running, and retrying counts the same consumption twice. Separate job identity, enqueue attempts and processing state.
Back to the practice route →Make a prediction first
- Wrap collections.deque in WorkQueue for FIFO. Each enqueued attempt starts at most once and moves from waiting to processing to success or failure. Continue consuming later items after a failure.
- Explicit retry creates a new attempt ID linked to the earlier failure; it is not the same consumption. Processing is sequential in one process, checking sample records and producing reports without automatic insertion.
- The separate fixed-capacity ring model must neither overwrite waiting items when full nor invent tasks when empty. Head and tail wrap by capacity. A general-purpose ring container is optional.
This is a deterministic teaching model. State checks inspect model invariants, not your prediction or Python code, and do not establish mastery. Model operation counts, browser time and Python implementation costs are different measures.
Controlled data-structure model
This checks model state only. It does not execute your Python or grade your prediction.
Unchecked or invalidated
Progressive learning hints
Hints are fixed teaching content. Their use is recorded.
Hint 1
Record each enqueue attempt ID. Should retrying a logical job reuse its attempt ID or create another?
Hint 2
Separate starting from finishing. Failure is a terminal state and must not prevent the next waiting item from starting.
Hint 3
Check that start order matches enqueue order and each attempt starts once. Wrap ring indices modulo capacity, using size to distinguish full from empty when head equals tail.
My Python draft
Save and export your draft here. Code is not executed or synced to the starter. Draft, input or strategy edits invalidate earlier model results and self-reports.
Local learning records
Saved only in this browser; export is available. No cross-device sync or proof of mastery. Earlier F01 and six-task records are preserved through migration.
- D02 opened: —
- Model check: Unchecked or invalidated
- Local tests (self-reported): —
- Highest hint level: 0/3
- Reference viewed: —
- Unaided variant (self-reported): —
Implement it in the same Campus Resource Organizer
from collections import deque
class WorkQueue:
def __init__(self):
self._waiting = deque()
def enqueue(self, task):
raise NotImplementedError
def step(self, checker=None):
raise NotImplementedError
An independent snapshot adds only this lab’s fault to the M1 baseline. The M2 starter contains all three labs’ unfinished parts. Keep reference answers separate from your own work.
python check_environment.py python -m unittest tests.test_d02 -v python -m unittest discover -s tests -v
Use Python 3.11+ and its standard library. Extract into a new directory. See the package’s exact intentional-failure list. A passing reference validates materials; you still need to run your own code.
Independent variant
Independently implement challenges.run_print_queue(initial_jobs, during_first=()): fail the first item, append another while processing and continue through every job. Add assertions for FIFO, completeness and continuation after failure. Explain why an undo stack would give the wrong order.
python -m unittest tests.test_m2_variants -v
Replace the skipped placeholder in tests/test_student_counterexamples.py with your own counterexample and explanation. Attempts using hints or references are not recorded as unaided.
Costs and model boundaries
Local deque operations at either end are typically O(1); job execution adds its own cost. Counts cover enqueue, start, completion, failure, retry and ring operations. Browser state snapshots and UI copies do not describe queue algorithm cost.
Reference explanation and answer
View reference explanation (records answer use)
FIFO determines start order, not success. Separating one attempt’s states from a new retry makes duplicate consumption observable. The model advances a head position rather than using array-copy cost to justify efficient dequeue. It makes no semaphore scheduling promise.
Download this lab’s reference (answer) · Version and source digest
Course references and related experiments
- F01: complete traversal
Check completeness through returned content and order.
- F04: failure contracts
Failure must not masquerade as success.
- Stack Lab: Undo Mistakes in a Campus Organizer
- Hash Table Lab: Collisions, Lookup, Index Keys and Costs