Apalis

Previous topic

Classes

Next topic

apalis.GroupHandler

apalis.Handler

class apalis.Handler(obj, affinity=None, param=None)

Saves the object into a forked process and provides an interface to interact with it.

Parameters
obj :

Object to be saved in a forked process.

affinityint, optional

cpu affinity of the process. This is usefull when the processed functions take between 1ms and 10ms to complete, by default None

Examples

>>> class A:
>>>     def f(self, x):
>>>         return x
>>>
>>> h = apalis.Handler(A())
>>> token = h.f(5)
>>> token()
5

Methods

multiple_run(tasks)

Executes several tasks.

run(tasks)

Runs the tasks and directly returns the ouputs.

single_run(task)

Executes a single task.

single_run(task)

Executes a single task.

Parameters
taskdict

Dictionary contatining the required fields to execute a function, get an attribute, etc.

Returns
Token

A token is returned. If it is called the main process will wait until the child process has returned the outputs of the function.

Examples

>>> h.single_run([{'name': '<function_name>', 'args': args, 'kwargs': kwargs, 'mode': 'run'}])
multiple_run(tasks)

Executes several tasks.

Parameters
taskdict

Dictionary contatining the required fields to execute a function, get an attribute, etc.

Returns
Token

A token is returned. If it is called the main process will wait until the child process has returned the outputs of the function.

Examples

>>> tasks = []
>>> tasks.append({'name': '<function_name>', 'args': args, 'kwargs': kwargs, 'mode': 'run'})
>>> tasks.append({'name': '<attribute_name>', 'mode': 'get_attr'})
>>> h.multiple_run(tasks)
run(tasks)

Runs the tasks and directly returns the ouputs. It is faster than multiple_run since it does not need to deal with Tokens.

Parameters
taskslist(dict)

List of tasks.

Returns
list

List with the output of the tasks.

Examples

>>> tasks = [{name': '<function_name>', 'args': args, 'kwargs': kwargs, 'mode': 'run'}, 
>>> taks += {name': '<attr_name>', 'value': 5, 'mode': 'setattr'}]
>>> h.run(tasks)
[result, attr]