Skip to content

Commit 1ff537c

Browse files
ssnlsoumith
authored andcommitted
Ignore FileNotFoundError when shutting down in data_queue.get (#5380)
* Ignore FileNotFoundError when shutting down in data_queue.get * Address @apaszke comments
1 parent c06c604 commit 1ff537c

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

torch/utils/data/dataloader.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,15 @@ def _shutdown_workers(self):
314314
if not self.shutdown:
315315
self.shutdown = True
316316
self.done_event.set()
317-
# if worker_manager_thread is waiting to put
318-
while not self.data_queue.empty():
319-
self.data_queue.get()
317+
# if worker_manager_thread is waiting to put, make place for it
318+
try:
319+
while not self.data_queue.empty():
320+
self.data_queue.get()
321+
except FileNotFoundError:
322+
# FileNotFoundError can happen when we rebuild the fd
323+
# fetched from the queue but the socket is already closed
324+
# from the worker side (e.g. due to Python shutting down).
325+
pass
320326
for _ in self.workers:
321327
self.index_queue.put(None)
322328
# done_event should be sufficient to exit worker_manager_thread,

0 commit comments

Comments
 (0)