PlasmaCalcs.tools.multiprocessing.Task
- class PlasmaCalcs.tools.multiprocessing.Task(f, args=None, kw=None, *, i=None)
Bases:
objecta single task, i.e. a function, args, & kwargs.Alternatively, calling self.apply_async(pool) enables to perform task in parallel,using the muliprocessing module.- f: callable
- The function to be called during task evaluation.if using ncpu > 1, f must be compatible with multiprocessing, i.e. it must be pickleable,e.g. it should be defined at the top level of a module or as a class method.
- args: iterable of args or non-iterable object.
- if iterable, will be interpreted as the list of args.if non-iterable, will use args = [args].
- i: any object
- optionally, index for this task.Useful when task appears inside a TaskContainer.
- __init__(f, args=None, kw=None, *, i=None)
Methods
__init__(f[, args, kw, i])apply_async(pool, *[, kw])get_kw([kw])implied(task_info, *[, force_kw])new_with([f, args, kw, i])- 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: 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.
- 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: bool
- applies 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_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))