Your small code snippet runs correctly on my machine:
dataset = TensorDataset(torch.randn(100, 1), torch.randn(100, 1))
loader = DataLoader(dataset, batch_size=2, shuffle=True, num_workers=2)

for batch_idx, batch in enumerate(loader):
    print(batch_idx, batch)
    if batch_idx == 1:
        break

> 0 [tensor([[ 0.7712],
          [-0.3303]]), tensor([[0.0505],
          [1.3738]])]
  1 [tensor([[-0.5104],
          [-0.5665]]), tensor([[-0.4806],
          [-0.7598]])]

Is the DataLoader with multiple workers working at all in your current setup and is only this small loop creating issues?