objwatch.mp_handls module

class objwatch.mp_handls.MPHandls(framework: str | None = None)[source]

Bases: object

Handles multi-process initialization and synchronization using specified multi-process frameworks.

Supported frameworks: - ‘torch.distributed’: PyTorch’s distributed environment for multi-GPU support. - ‘multiprocessing’: Python’s built-in multiprocessing for parallel processing.

Manages process synchronization and provides the index of the current process.

__init__(framework: str | None = None) None[source]

Initializes the handler with the specified framework.

Parameters:

framework (Optional[str]) – The multi-process framework to use.

_check_initialized() None[source]

Verifies if the selected multi-process framework is initialized. Supports built-in frameworks and allows for custom framework extensions.

sync() None[source]

Synchronizes processes across all indices.

get_index() int | None[source]

Returns the index of the current process.

Returns:

The index of the current process (e.g., rank in distributed environments). Returns None if the framework is not initialized.

Return type:

Optional[int]

is_initialized() bool[source]

Checks if the multi-process framework has been initialized.

Returns:

True if the framework is initialized, False otherwise.

Return type:

bool

_check_init_torch() None[source]

Checks if the PyTorch distributed environment is initialized for multi-GPU support. If initialized, sets the current process index and synchronization function.

_check_init_multiprocessing() None[source]

Checks if Python’s built-in multiprocessing is initialized. If initialized, sets the current process index and synchronization function.