brain_pipe.utils.parallellization.MultiprocessingSingleton

class MultiprocessingSingleton

Bases: object

Singleton class for multiprocessing.

Attributes

locks

manager

to_clean

__init__()

Methods

__init__()

clean()

Clean up the multiprocessing pools.

get_lock(id_str)

Create or get a lock for multiprocessing.

get_map_fn(nb_processes[, callback, ...])

Create a map function for multiprocessing.

classmethod clean()

Clean up the multiprocessing pools.

classmethod get_lock(id_str)

Create or get a lock for multiprocessing.

Parameters:

id_str (str) – Identifier for the lock. If the lock does not already exist in self.locks, it will be created and added to self.locks.

Return type:

multiprocessing.Lock

classmethod get_map_fn(nb_processes, callback: ~brain_pipe.utils.parallellization.ProgressCallbackFn = <brain_pipe.utils.parallellization.SimpleCallbackFn object>, maxtasksperchild=None)

Create a map function for multiprocessing.

Parameters:
  • nb_processes (int) – Number of processes to use. If -1, use all available cores. If 0, do not use multiprocessing.

  • callback (ProgressCallbackFn) – Callback function to track the progress of the multiprocessing.

  • maxtasksperchild (Optional[int]) – Maximum number of tasks per child process.

Returns:

Map function.

Return type:

Callable