FastSurferCNN.utils.parallel¶
- class FastSurferCNN.utils.parallel.SerialExecutor[source]¶
Represent a serial executor.
Methods
map(fn, *iterables[, timeout, chunksize])The map function.
shutdown([wait, cancel_futures])Clean-up the resources associated with the Executor.
submit(_SerialExecutor__fn, *args, **kwargs)A callable function that returns a Future representing the result.
- map(fn, *iterables, timeout=None, chunksize=-1)[source]¶
The map function.
- Parameters:
- Returns:
Iterator[_T]An iterator that yields the results of applying ‘fn’ to the items of ‘iterables’.
- shutdown(wait=True, *, cancel_futures=False)[source]¶
Clean-up the resources associated with the Executor.
It is safe to call this method several times. Otherwise, no other methods can be called after this one.
- Args:
- wait: If True then shutdown will not return until all running
futures have finished executing and the resources used by the executor have been reclaimed.
- cancel_futures: If True then shutdown will cancel all pending
futures. Futures that are completed or running will not be cancelled.
- submit(_SerialExecutor__fn, *args, **kwargs)[source]¶
A callable function that returns a Future representing the result.
- Parameters:
- __fn
Callable[…,_T] A callable function to be executed.
- *args
Potential arguments to be passed to the callable function.
- **kwargs
Keyword arguments to be passed to the callable function.
- __fn
- Returns:
- “Future[
_T]” A Future object representing the execution result of the callable function.
- “Future[
- FastSurferCNN.utils.parallel.get_num_threads()[source]¶
Determine the number of available threads.
Tries to get the process’s CPU affinity for usable thread count; defaults to total CPU count on failure.
- Returns:
intNumber of threads available to the process or total CPU count.
- FastSurferCNN.utils.parallel.iterate(pool, func, iterable)[source]¶
Iterate over iterable, yield pairs of elements and func(element).
- Parameters:
- pool
Executor The Executor object (dummy object to have a common API with pipeline).
- func
callable() Function to use.
- iterable
Iterable Iterable to draw objects to process with func from.
- pool
- Yields:
- element
_Ti Elements
_TResults of func corresponding to element: func(element).
- element
- FastSurferCNN.utils.parallel.pipeline(pool, func, iterable, *, pipeline_size=1)[source]¶
Pipeline a function to be executed in the pool.
Analogous to iterate, but run func in a different thread for the next element while the current element is returned.
- Parameters:
- pool
Executor Thread pool executor for parallel execution.
- func
callable() Function to use.
- iterable
Iterable Iterable containing input elements.
- pipeline_size
int, default=1 Size of the processing pipeline.
- pool
- Yields:
- element
_Ti Elements
_TResults of func corresponding to element: func(element).
- element
- FastSurferCNN.utils.parallel.set_num_threads(threads, wait_finish=False)[source]¶
Sets the number of threads to use.
- FastSurferCNN.utils.parallel.shutdown_executors(wait=True, *, cancel_futures=False)[source]¶
This is a cleanup function and should only be called at the end of a script!
This first shuts down the
process_executorand then thethread_executor.Notes
The executors are not shut down at the same time, but rather, if wait is True, we first wait for the
process_executorto “finish” shutting down.