Multiprocessing your Functions

Flock supports the following list of functions:
  • Lambdas
  • Instance methods
  • Class methods
  • Regular functions

If your function needs a connection to any database to perform its computation, please use the DatabaseAsync class.

class flockmp.FunctionAsync

FunctionAsync is a class to apply and manage multiprocessing tasks within functions.

classmethod apply(iterator, function, poolSize=5)

Method apply() executes a function asynchronously given an iterator.

Parameters:
  • iterator (iter) – variable in which the function will be applied.
  • function (func) – a function in which is desired to be ran multi-processed.

Returns the list with the results of function(iterator).

Example

_list = list(range(2000))
res = FunctionAsync.apply(_list, lambda x: x ** 2 / 10)