Skip to content

Commit 1ac19ea

Browse files
ssnlsoumith
authored andcommitted
Fix dataloader._shutdown_workers if not all workers are started (#23762)
1 parent 93a8dda commit 1ac19ea

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

torch/utils/data/dataloader.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,10 @@ def _shutdown_workers(self):
896896

897897
# Exit workers now.
898898
self.workers_done_event.set()
899-
for worker_id in range(self.num_workers):
899+
for worker_id in range(len(self.workers)):
900+
# Get number of workers from `len(self.workers)` instead of
901+
# `self.num_workers` in case we error before starting all
902+
# workers.
900903
if self.workers_status[worker_id]:
901904
self._shutdown_worker(worker_id)
902905
for w in self.workers:

0 commit comments

Comments
 (0)