process_pool_lock

process_pool_lock#

class brainpy.running.process_pool_lock(func, all_params, num_process)[source]#

Run multiple models in multi-processes with lock.

Sometimes, you want to synchronize the processes. For example, if you want to write something in a document, you cannot let multiprocess simultaneously open this same file. So, you need add a lock argument in your defined func:

def some_func(..., lock, ...):
    ... do something ..

    lock.acquire()
    ... something cannot simultaneously do by multi-process ..
    lock.release()

In such case, you can use process_pool_lock() to run your model.

Note

This multiprocessing function should be called within a if __main__ == ‘__main__’: syntax.

Parameters:
  • func (callable) – The function to run model.

  • all_params (list, tuple, dict) – The parameters of the function arguments.

  • num_process (int) – The number of the processes.

Returns:

results – Process results.

Return type:

list