STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
engine.layerx.pool.WorkerPool Class Reference

Public Member Functions

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)

Public Attributes

 workers = max(1, int(workers))

Protected Attributes

Any _executor = None
bool _cancelled = False

Detailed Description

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.

Constructor & Destructor Documentation

◆ __init__()

None engine.layerx.pool.WorkerPool.__init__ ( self,
int workers )

Definition at line 47 of file pool.py.

Member Function Documentation

◆ __enter__()

"WorkerPool" engine.layerx.pool.WorkerPool.__enter__ ( self)

Definition at line 118 of file pool.py.

◆ __exit__()

None engine.layerx.pool.WorkerPool.__exit__ ( self,
Any exc_type,
Any exc,
Any tb )

◆ close()

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__().

◆ map()

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.

◆ parallel()

bool engine.layerx.pool.WorkerPool.parallel ( self)

Definition at line 64 of file pool.py.

References _executor.

Member Data Documentation

◆ _cancelled

bool engine.layerx.pool.WorkerPool._cancelled = False
protected

Definition at line 61 of file pool.py.

Referenced by close(), and map().

◆ _executor

Any engine.layerx.pool.WorkerPool._executor = None
protected

Definition at line 54 of file pool.py.

Referenced by close(), map(), and parallel().

◆ workers

engine.layerx.pool.WorkerPool.workers = max(1, int(workers))

Definition at line 53 of file pool.py.


The documentation for this class was generated from the following file:
  • EngineDesign/engine/layerx/pool.py