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 must be specified as a number (lower = higher priority).


Simple collection of functions.

from neotasker import FunctionCollection

def error(**kwargs):
   import traceback

startup = FunctionCollection(on_error=error)

def f1():
    return 1

def f2():
    return 2

# lower number = higher priority
def f3():
    return 3

result, all_ok = startup.execute()
class neotasker.FunctionCollection(**kwargs)
  • on_error – function, launched when function in collection raises an exception
  • on_error_kwargs – additional kwargs for on_error function
  • include_exceptions – include exceptions into final result dict
append(f, priority=None)

Append function without annotation

  • f – function
  • priority – function priority

Run all functions in collection

Returns:a tuple { ‘<function>’: ‘<function_return>’, …}, ALL_OK where ALL_OK is True if no function raised an exception

Remove function

Parameters:f – function

Run all functions in collection

Returns:result dict as

{ ‘<function>’: ‘<function_return>’, … }