Define objects using classes instead of namedtuples in torch.utils.data._utils.worker (#45870)
Summary:
This PR fixes a bug when torch is used with pyspark, by converting namedtuples in `torch.utils.data._utils.worker` into classes.
Before this PR, creating an IterableDataset and then running `list(torch.utils.data.DataLoader(MyIterableDataset(...), num_workers=2)))` will not terminate, if pyspark is also being used. This is because pyspark hijacks namedtuples to make them pickleable ([see here](https://github.com/apache/spark/blob/master/python/pyspark/serializers.py#L370)). So `_IterableDatasetStopIteration` would be modified, and then the check at [this line in dataloader.py](https://github.com/pytorch/pytorch/blob/5472426b9f85c8107aade5d256cf4cde572eab5c/torch/utils/data/dataloader.py#L1072) is never true.
Converting the namedtuples to classes avoids this hijack and allows the iteration to correctly stop when signaled.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/45870
Reviewed By: ngimel
Differential Revision: D24162748
Pulled By: albanD
fbshipit-source-id: 52f009784500fa594b2bbd15a8b2e486e00c37fb