Where did the first score go when the second job failed?
A program asked for two scores. The first job finished and the worker recorded 80 points. The second job stopped with an error. When the program went to collect the scores, even the 80 was missing.
The worker had been asked to send back one list with both answers. The error stopped it before it could return that list. We tried sending the same jobs three different ways to see when the first score made it back.
In this test, the program that asks for the work is called the caller. It hands jobs to another process, the worker, and waits for the answers to come back.
In CPython 3.12.15, ProcessPoolExecutor.map(..., chunksize=2) groups two calls into one task. The worker runs them in sequence and returns their results together as a list. If the second call raises an exception, the task fails before returning that list, so the caller never receives the first score. Python documentation · Pinned CPython implementation
One completed job, three ways to collect its score
We sent the same two jobs to a worker three ways. We wrote case a to return 80 points and case b to raise an error called a ValueError. The worker recorded both events in its log.
The table compares the three methods when case b fails. In the last row, the caller gets a separate object for each job, called a future. It can use the first future to collect the score and the second to find out what went wrong.
| Submission | Worker events | Caller receives |
|---|---|---|
map, chunk size 1 | Case a returns, case b raises | Score 80, then the error |
map, chunk size 2 | Case a returns, case b raises | Error before any score |
One submit() per case | Case a returns, case b raises | Score 80 and a separate failed future |
How to keep a finished score
When both jobs succeeded, all three submission methods returned both scores. When case b failed, the chunk of two returned an error before delivering a’s score. With a separate future for each case, the caller could retrieve the 80 from a’s future and handle the exception from b’s future separately.
For failures like the controlled exception in this example, submitting one future per case keeps the results separately retrievable. Another approach to consider is catching expected exceptions inside the worker and returning an explicit success or error status for each case.
Compare the case IDs delivered to the caller with the worker log. A reliable log entry showing that a case finished or raised an error lets you distinguish a completed but undelivered score from a case that produced no score.
Reproduce the result
Run python -I -B replay.py with CPython 3.12.15. The fixture uses one worker, the spawn process context and two synthetic cases.
To check the saved observations, run python -I -B verify.py beside them. The verifier checks six runs, including successful and failing cases: 12 worker events, eight delivered scores and one completed score that the caller never received. Replay · Observations · Verifier