stouputils.parallel.common module#
- nice_wrapper(
- args: tuple[int, Callable[[T], R], T],
Wrapper that applies nice priority then executes the function.
- Parameters:
args (tuple) – Tuple containing (nice_value, func, arg)
- Returns:
Result of the function execution
- Return type:
R
- set_process_priority(nice_value: int) None[source]#
Set the priority of the current process.
- Parameters:
nice_value (int) – Unix-style priority value (-20 to 19)
- starmap(
- args: tuple[Callable[[T], R], list[T]],
Private function to use starmap using args[0](*args[1])
- Parameters:
args (tuple) – Tuple containing the function and the arguments list to pass to the function
- Returns:
Result of the function execution
- Return type:
object
- delayed_call(
- args: tuple[Callable[[T], R], float, T],
Private function to apply delay before calling the target function
- Parameters:
args (tuple) – Tuple containing the function, delay in seconds, and the argument to pass to the function
- Returns:
Result of the function execution
- Return type:
object
- handle_parameters(
- func: Callable[[T], R] | list[Callable[[T], R]],
- args: list[T],
- use_starmap: bool,
- delay_first_calls: float,
- max_workers: int,
- desc: str,
- color: str,
Private function to handle the parameters for multiprocessing or multithreading functions
- Parameters:
func (Callable | list[Callable]) – Function to execute, or list of functions (one per argument)
args (list) – List of arguments to pass to the function(s)
use_starmap (bool) – Whether to use starmap or not (Defaults to False): True means the function will be called like func(*args[i]) instead of func(args[i])
delay_first_calls (int) – Apply i*delay_first_calls seconds delay to the first “max_workers” calls. For instance, the first process will be delayed by 0 seconds, the second by 1 second, etc. (Defaults to 0): This can be useful to avoid functions being called in the same second.
max_workers (int) – Number of workers to use
desc (str) – Description of the function execution displayed in the progress bar
color (str) – Color of the progress bar
- Returns:
Tuple containing the description, function, and arguments
- Return type:
tuple[str, Callable[[T], R], list[T]]