|
| None | __init__ (self, int workers) |
| bool | parallel (self) |
| List[Dict[str, Any]] | map (self, Callable[[Any], Dict[str, Any]] fn, Sequence[Any] args, *, Callable[[], bool] cancelled=lambda:False, Optional[Callable[[int, Dict[str, Any]], None]] on_result=None) |
| None | close (self, bool cancelled=False) |
| "WorkerPool" | __enter__ (self) |
| None | __exit__ (self, Any exc_type, Any exc, Any tb) |
Spawned workers for whole burns. ``with WorkerPool(n) as pool: pool.map(fn, args, ...)``.
With one worker, or where processes cannot be spawned (a sandbox), it runs in this process.
Definition at line 41 of file pool.py.
| None engine.layerx.pool.WorkerPool.close |
( |
| self, |
|
|
bool | cancelled = False ) |
Shut the workers down. On a cancel they are terminated: a burn in flight is 30-60 s,
and leaving it running after the job released its slot stacks the next job on top of it.
Definition at line 102 of file pool.py.
References _cancelled, and _executor.
Referenced by __exit__().
| List[Dict[str, Any]] engine.layerx.pool.WorkerPool.map |
( |
| self, |
|
|
Callable[[Any], Dict[str, Any]] | fn, |
|
|
Sequence[Any] | args, |
|
|
* | , |
|
|
Callable[[], bool] | cancelled = lambda: False, |
|
|
Optional[Callable[[int, Dict[str, Any]], None]] | on_result = None ) |
``fn`` over ``args``, results in order. ``on_result(done_count, result)`` as each lands.
Raises :class:`Cancelled` within ``POLL_S`` of ``cancelled()`` turning true.
Definition at line 67 of file pool.py.
References _cancelled, and _executor.