PlasmaCalcs.tools.multiprocessing.TaskContainer

class PlasmaCalcs.tools.multiprocessing.TaskContainer(tasks, *args_super, assign_task_idx=True, printable_process_name=None, errors_ok=False, result_missing=RESULT_MISSING, **kw_super)

Bases: Container

a container for multiple tasks; each Task is a function, args, & kwargs.
Calling self will perform all tasks, returning the result (and updating self.result as well).
tasks: iterable of Task objects
Tasks to perform. Expected type depends on subclass, see e.g. TaskList or TaskArray.
assign_task_idx: bool
whether to assign task.i for each task, based on its position in self.
printable_process_name: None or str
include in progress update printouts. If None, use a reasonable default.
errors_ok: bool, Exception type, or tuple of Exception types
whether it is okay for some tasks to produce certain errors.
False –> crash if any task crashes. Equivalent to errors_ok=().
True –> except Exception (not BaseException, though). Equivalent to errors_ok=Exception.
Exception type or tuple –> except this type (or these types, if tuple).
result_missing: any object
result to record for tasks which crash (if errors_ok!=False). Default RESULT_MISSING.
__init__(tasks, *args_super, assign_task_idx=True, printable_process_name=None, errors_ok=False, result_missing=RESULT_MISSING, **kw_super)
should set self.data = something related to stuff.

Methods

__init__(tasks, *args_super[, ...])

assign_task_idx()

coarsen([ncoarse, idx])

enumerate([idx])

errors_ok_tuple([value])

init_result()

new_empty([fill])

size([idx])

Attributes

errors_ok

printable_process_name

tasks

assign_task_idx()
assign task.i for tasks in self, based on their positions in self.
coarsen(ncoarse=5, *, idx=None)
return a TaskPartition containing TaskGroups of size ncoarse.
Useful for coarsening a TaskContainer for more efficient multiprocessing;
grouping tasks together can reduce the overhead of multiprocessing,
while still allowing for parallel processing as the groups are run in parallel.
if idx is provided, only group the tasks with those indices.
enumerate(idx=None)
iterate through i in idx, yielding (i, self[i]) pairs.
If idx is None, iterate through all objs in self (see self._enumerate_all).
property errors_ok
tuple of Exception types which are okay for tasks to raise.
setting self.errors_ok = False –> use empty tuple, i.e. no errors are okay.
setting self.errors_ok = errtype –> use errors_ok = (errtype,).
setting errors_ok will crash if it includes any parent class of KeyboardInterrupt,
e.g. errors_ok=BaseException will crash, but errors_ok=Exception will be fine.
See also: self.errors_ok_tuple
errors_ok_tuple(value=UNSET)
returns tuple of okay errors. UNSET –> self.errors_ok.
False –> (). errtype –> (errtype,).
if result includes any parent class of KeyboardInterrupt, raises InputError.
e.g. errors_ok_tuple(BaseException) will crash, but errors_ok_tuple(Exception) will be fine.
init_result()
set self.result = container with similar shape as self, filled with RESULT_MISSING.
Then, return self.result.
The idea is that self.result[idx] will correspond to the result of self[idx].
new_empty(fill=UNSET)
return a new container of the same shape as self, filled with the value fill.
The implementation will depend on the container type; subclass should implement.
property printable_process_name
return the name to be used for progress updates, if any.
If None, use the default: “[type(self)].__call__”.
size(idx=None)
return the number of objects in the container, or in idx if provided.
task_cls

alias of Task

property tasks
alias to data