Task collections

Task collections are useful when you need to run a pack of tasks e.g. on program startup or shutdown. Currently collections support running task functions only either in a foreground (one-by-one) or as the threads.

Function priority can be specified either as TASK_* (e.g. TASK_NORMAL) or as a number (lower = higher priority).


Simple collection of functions.

from atasker import FunctionCollection, TASK_LOW, TASK_HIGH

def error(**kwargs):
   import traceback

startup = FunctionCollection(on_error=error)

def f1():
    return 1

def f2():
    return 2

def f3():
    return 3

result, all_ok = startup.execute()


Same as function collection, but stored functions are started as tasks in threads.

Methods execute() and run() return result when all tasks in collection are finished.