01 / Reproduce
Reproduce the swap
Extract the practice ZIP and open PowerShell or a terminal in the extracted folder. Use Python 3.10 or later. The exercise uses the standard library and runs offline.
python batch.py
python check.py
submit() returns a Future for each call. The first worker waits on an event. With two workers, the collector can see the second future finish and then release the first. The script prints submission order, completion order, and both mappings. The check script verifies six assertions, including the error case below.
submission_ids = [ticket["id"] for ticket in tickets]
outcomes = [outcome for _, outcome in completed]
by_position = dict(zip(submission_ids, outcomes, strict=True))
The input IDs are T-201, T-202. The completion order is T-202, T-201. Both lists have two items, so zip(..., strict=True) accepts them even though their positions refer to different tickets.
02 / Inspect
Keep the ticket ID with the future
At submission, store the original ticket ID under its future. as_completed() yields each finished or cancelled future. The lab saves each completed future with its outcome and then looks up that exact future to identify the ticket.
future_to_id = {
pool.submit(summarize, first, gate): first["id"],
pool.submit(summarize, second): second["id"],
}
# Each (future, outcome) pair comes from the completion loop.
by_future = {future_to_id[future]: outcome for future, outcome in completed}
Read the two mappings from the same run.
T-201 by position Receipt missing.
T-201 by future Reset link expired.
T-202 by position Reset link expired.
T-202 by future Receipt missing.
The ID comes from the input and stays in the application. The worker only returns a summary. If the dashboard needs submission order for display, look up the finished outcomes by ID in that order after collection.
03 / Make it your own
Give one ticket a failed job
- Copy
tickets.jsontomy-tickets.json. - Change the second ticket’s
summaryto JSONnull. The fixture worker raises aValueErrorand the collector records it as a readable error. - Run the modified file. Check the ID that gets the error under each mapping.
python batch.py my-tickets.json
The positional mapping blames T-201. The future mapping records the error under T-202, the job that actually failed. For your own batch, start with two fictional rows from its input format and assert the association for both a success and a failure.
Boundaries
Apply the mapping in a batch
The practice script expects two rows with unique IDs. Its event only controls the demonstration. In your collector, assign a unique ID per submitted job and preserve it when you handle an error from Future.result(). Review the output separately for summary quality before any write. This lab tested local result association and the authored failure case. Model calls, dashboard updates, provider timeouts, retries, and performance remain untested.
Primary sources / Checked November 12, 2026
Read the Python references
- What submission returns and when the iterator yields it. Python 3.13 reference for
submit()andas_completed() - How a worker exception reaches the collector. Python 3.13 reference for
Future.result() - How the first worker waits for a signal. Python 3.13 guide to event objects
Downloads / Practice and social files

