Skip to content

Commit

Permalink
[DataLoader2] Ensure finalize and finalize_iteration are called durin…
Browse files Browse the repository at this point in the history
…g shutdown/exception

ghstack-source-id: eb65f0a99f8dbc6c4b741b0d5d295ed082a08bdc
Pull Request resolved: #846
  • Loading branch information
NivekT committed Oct 21, 2022
1 parent 222877d commit 3836b66
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions torchdata/dataloader2/dataloader2.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ def __next__(self) -> T_co:
if self.dataloader.reading_service is not None:
self.dataloader.reading_service.finalize_iteration()
raise
except Exception:
if self.dataloader:
self.dataloader.shutdown()
raise
else:
if self.dataloader.reading_service is not None:
self.dataloader.reading_service.finalize_iteration()
Expand Down Expand Up @@ -198,6 +202,7 @@ def shutdown(self) -> None:
self._datapipe_iter = None
if not self._terminated:
if self.reading_service is not None:
self.reading_service.finalize_iteration()
self.reading_service.finalize()
self._terminated = True

Expand Down

0 comments on commit 3836b66

Please sign in to comment.