Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion torch/utils/data/_utils/pin_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def _pin_memory_loop(in_queue, out_queue, device_id, done_event):
except queue.Empty:
continue
idx, data = r
if not isinstance(data, ExceptionWrapper):
if not done_event.is_set() and not isinstance(data, ExceptionWrapper):
try:
data = pin_memory(data)
except Exception:
Expand Down
6 changes: 5 additions & 1 deletion torch/utils/data/dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,9 +886,13 @@ def _shutdown_workers(self):
# corrupted data in `worker_result_queue` which `pin_memory_thread`
# reads from.
if hasattr(self, 'pin_memory_thread'):
self.pin_memory_thread_done_event.set()
# Use hasattr in case error happens before we set the attribute.
self.pin_memory_thread_done_event.set()
# Send something to pin_memory_thread in case it is waiting
# so that it can wake up and check `pin_memory_thread_done_event`
self.worker_result_queue.put((None, None))
self.pin_memory_thread.join()
self.worker_result_queue.close()

# Exit workers now.
self.workers_done_event.set()
Expand Down