import pymizu
with pymizu.PoolExecutor.create(2) as ex:
futures = [ex.submit(pow, 2, i) for i in range(4)]
results = [f.result() for f in futures]
results[1, 2, 4, 8]
A concurrent.futures.Executor over a pymizu pool.
Usage
submit() returns a real concurrent.futures.Future: wait / as_completed / result(timeout) / asyncio.wrap_future and the stdlib base Executor.map all work unchanged, so code written against ProcessPoolExecutor drops in. create() spawns an owned pool instead.
pool: pymizu.PoolThe pool to wrap; its lifetime stays with its owner unless stop_pool is set — then shutdown() stops it.
stop_pool: bool = Falseshutdown() stops the wrapped pool.
Deltas from stdlib semantics: a task’s failure surfaces as pymizu.TaskError (the remote error envelope); Future.running() is always False (futures resolve at completion); cancellation is advisory, mirroring Task.cancel() — and shutdown(cancel_futures=True) cancels every outstanding future, since the pool exposes no queued-versus-running signal (a running task completes, but its result is discarded). An infrastructure failure (e.g. the wrapped pool is stopped from under the executor) fails every outstanding future; later submissions raise instead of queueing onto a broken executor. Resolution — including any add_done_callback callables — runs on the core’s listener thread, the same discipline as the stdlib executors’ management thread: keep callbacks short, and never block one on the pool itself. map is the stdlib base implementation over submit — for bulk maps, Pool.map is the faster path.
Use as a drop-in concurrent.futures.Executor:
| Name | Description |
|---|---|
| create() | Spawn an owned pool — |
| shutdown() | Stdlib shutdown. |
| submit() | Schedule fn(*args, **kwargs) on the pool. |
Spawn an owned pool —
Usage
Pool.create() with workers and pool_kwargs — and wrap it; shutdown() stops it.
workers: int = 1Number of worker processes for the pool.
pool_kwargs: _Any = {}Pool.create().
A PoolExecutor wrapping the spawned pool.Stdlib shutdown.
Usage
wait: bool = TrueWait for the outstanding futures.
cancel_futures: bool = Falsestop_pool was set.
Schedule fn(*args, **kwargs) on the pool.
Usage
fn: _Callable[…, _Any]The callable to run.
args: _Any = ()Positional arguments for fn.
kwargs: _Any = {}fn.
A concurrent.futures.Future resolving with the result. RuntimeErrorAfter shutdown.
pymizu.MizuError