Search RU
Tasks / Concurrency / Parallel map
Statement hard

Parallel map

`parallel_map(func, items, workers=4)` runs functions in a thread pool and
returns a list of results **in input order**.

Write tests:

- the order is preserved even when the functions finish in a different order;
- an empty list gives an empty result;
- an exception from a function propagates to the caller;
- the functions really run in parallel: two of them meet at a
`threading.Barrier`, and a sequential implementation must not pass.

The barrier must have a timeout so the test does not hang.

concurrencythreadsfutures
test_solution.py Python 3.14
AI mentor

The AI mentor is available after you log in: it sees your attempt history and does not spend resources on anonymous requests.

Log in and ask
Hints 1 of 3 unlocked · attempts: 0
Hint 1

How do you prove parallelism without `sleep`? A barrier that two functions meet
at is the cheapest way.

Hint 2 — unlocks after 1 attempt
Hint 3 — unlocks after 3 attempts