Map
A staged, submitted map; collects exactly once, through this handle.
Usage
Map(
pool,
plan,
)Returned by Pool.map() and PreparedMap.run(). collect() blocks. collect_async() or await resolves one asyncio Future when the results arrive (not on a streaming map, whose sliding task window advances in the blocking collect loop). cancel() stops the run: workers halt within about one batch and the outstanding tasks are cancelled. A dropped uncollected handle cancels at GC, so no run of fn is wasted. One collection per handle, as for tasks.
Methods
| Name | Description |
|---|---|
| cancel() | Stop the run: workers halt within about one batch. |
| collect() | Block for the map’s results; collect exactly once. |
| collect_async() | Resolve one asyncio.Future with the results collect() returns. |
cancel()
Stop the run: workers halt within about one batch.
Usage
cancel()Advisory, as Task.cancel(): the outstanding tasks are cancelled, so a queued task is skipped, and a running batch completes with its result dropped. A pending collect, blocking or async, ends with CancelledError. Safe to call more than once.
collect()
Block for the map’s results; collect exactly once.
Usage
collect(timeout=None)Parameters
timeout: float | None = None-
Seconds to wait for completion; None waits indefinitely. On expiry the outstanding work is cancelled and the
TIMEOUTSentinelis returned rather than raised.
Returns
The results, with the same shapes and outcomes as-
PreparedMap.run()documents.
collect_async()
Resolve one asyncio.Future with the results collect() returns.
Usage
collect_async()The event-driven collect, which never blocks or polls. An element error rejects with its index. Cancelling the Future detaches the waiter, so the handle can be collected blocking again, and never cancels the map (only cancel() does). A streaming map refuses, because its sliding task window advances in the blocking collect loop.