Hi,
I tried this-
class MyDataset(Dataset):
    def __init__(self):
        self.bob = [0,1,2]
    def __len__(self):
        return len(self.bob)
    def __getitem__(self, idx):
        print(f'idx = {idx}')
        return self.bob[idx]

dataset = DataLoader(MyDataset(), batch_size = 1, shuffle = True, num_workers = 0)

for i, data in enumerate(dataset):
    print(i)
    print(data)

And got the following output that did not loop infinitely-
idx = 1
0
tensor([1])
idx = 0
1
tensor([0])
idx = 2
2
tensor([2])

Is your DataLoader() correct, because your custom Dataset looks correct.