def _try_load(path_data: str, trials: int = 30, delta: float = 1.0) -> tuple[Tensor, Tensor]:
        """Resolving loading from the same time from multiple concurrent processes."""
        res, exception = None, None
        assert trials, "at least some trial has to be set"
        assert os.path.isfile(path_data), f"missing file: {path_data}"
        for _ in range(trials):
            try:
                res = torch.load(path_data)
            # todo: specify the possible exception
            except Exception as ex:
                exception = ex
                time.sleep(delta * random.random())  # noqa: S311
            else:
                break
        assert res is not None
        if exception is not None:
            # raise the caught exception
            raise exception
        return res
Resolving loading from the same time from multiple concurrent processes.
src/lightning/pytorch/demos/mnist_datamodule.py