TaskGroup
- class PlasmaCalcs.tools.multiprocessing.TaskGroup(tasks, *, i=None, errors_ok=(), result_missing=RESULT_MISSING)
Bases:
Task,ContainerOfDicttreats a dict of Tasks as if it was a single Task.
Helps with coarsen. Users probably don’t need to think about TaskGroup directly.
tasks: dict of Tasks
errors_ok: tuple of Exception typesthe exception types for which to return result_missing instead of crashing, in case of error.result_missing: any objectresult to record for tasks which crash (if errors_ok!=False). Default RESULT_MISSING.Methods
__call__(**kw)perform the task, i.e. return f(*args, **kw).
apply_async(pool, *[, kw])perform the task asynchronously, i.e. pool.apply_async(...).
enumerate([idx])iterate through i in idx, yielding (i, self[i]) pairs.
f(*args__None, **kw)perform all tasks in self, returning the results (as a dict)
get_kw([kw])gets self.kw, but updated with values from kw.
implied(task_info, *[, force_kw])return the Task implied from task_info.
new_empty([fill])return a new dict of the same shape as self, filled with the value fill.
new_with([f, args, kw, i])return a new Task, with the given inputs.
size([idx])return the number of objects in the container, or in idx if provided.
iterate through all objs in self, yielding (i, self[i]) pairs.
the number of objects in this container.
Attributes
argskwalias to data
- __call__(**kw)
perform the task, i.e. return f(*args, **kw).
kw: dict
kwargs for task will be task.kw, but updated with kw.E.g. if task.kw = {‘x’: 1}, and kw = {‘y’: 2}, –> task called with x=1, y=2.
- _enumerate_all()
iterate through all objs in self, yielding (i, self[i]) pairs.
- _size_all()
the number of objects in this container. == len(self.data)
- apply_async(pool, *, kw={})
perform the task asynchronously, i.e. pool.apply_async(…)
Equivalent to pool.apply_async(self.f, args=self.args, kwds=self.kw)kw: dictkwargs for task will be task.kw, but updated with kw.E.g. if task.kw = {‘x’: 1}, and kw = {‘y’: 2}, –> task called with x=1, y=2.
- 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).
- f(*args__None, **kw)
perform all tasks in self, returning the results (as a dict)
- get_kw(kw={})
gets self.kw, but updated with values from kw. (doesn’t alter self.kw)
[EFF] if kw is empty, return self.kw instead of making a copy.
- classmethod implied(task_info, *, force_kw=True, **kw_init)
return the Task implied from task_info.
task_info: Task, iterable, or callable.Task –> return task_info, unchanged (unless force_kw and len(kw_init)>0).if task_info is not an instance of cls but it is a Task, raise TypeError.iterable –> return Task(*task_info).callable –> return Task(task_info).force_kw: boolapplies if kw_init provided and task_info is a Task…True –> return task_info.new_with(**kw_init)False –> return task_info, unchanged.kw_init: pass to Task(…, **kw_init) if task_info is not already a Task.
- new_empty(fill=UNSET)
return a new dict of the same shape as self, filled with the value fill.
- new_with(f=UNSET, args=UNSET, kw=UNSET, i=UNSET)
return a new Task, with the given inputs. Use value from self for UNSET inputs.
E.g. Task(f, [5,6]).new_with(f=g, kw=dict(y=7)) –> Task(g, [5,6], dict(y=7))
- size(idx=None)
return the number of objects in the container, or in idx if provided.
- property tasks
alias to data