def worker_init(worker_id):
        """Initializes a worker during inference/training.

        This method is used as the ``worker_init_fn`` parameter for
        :class:`torch:torch.utils.data.DataLoader`.

        Args:
            worker_id: the worker ID
        """
        import fiftyone.core.odm.database as food

        # Ensure that each process creates its own MongoDB clients
        # https://pymongo.readthedocs.io/en/stable/faq.html#using-pymongo-with-multiprocessing
        # pylint:disable-next=protected-access
        food._disconnect()

        torch_dataset = torch.utils.data.get_worker_info().dataset

        if torch_dataset._samples is not None:
            raise ValueError(
                "worker_init() called after samples have been loaded. This "
                "should not happen!"
            )

        torch_dataset._load_samples()
Initializes a worker during inference/training.

        This method is used as the ``worker_init_fn`` parameter for
        :class:`torch:torch.utils.data.DataLoader`.

        Args:
            worker_id: the worker ID
        
fiftyone/utils/torch.py