Skip to content

Workers

Reference information for the utils Workers API.

eva.core.utils.workers.main_worker_only

Function decorator which will execute it only on main / worker process.

Source code in src/eva/core/utils/workers.py
def main_worker_only(func: Callable) -> Any:
    """Function decorator which will execute it only on main / worker process."""

    def wrapper(*args: Any, **kwargs: Any) -> Any:
        """Wrapper function for the decorated method."""
        if is_main_worker():
            return func(*args, **kwargs)

    return wrapper

eva.core.utils.workers.is_main_worker

Returns whether the main process / worker is currently used.

Source code in src/eva/core/utils/workers.py
def is_main_worker() -> bool:
    """Returns whether the main process / worker is currently used."""
    process = multiprocessing.current_process()
    return process.name == "MainProcess"