Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: throw exception in consumer thread #4583

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
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
12 changes: 7 additions & 5 deletions deepmd/pd/utils/dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,13 @@
self._max_len = max_len #

def run(self) -> None:
for item in self._source:
self._queue.put(item) # Blocking if the queue is full

# Signal the consumer we are done.
self._queue.put(_sentinel)
try:
for item in self._source:
self._queue.put(item) # Blocking if the queue is full
except Exception as e:
self._queue.put(e)

Check warning on line 265 in deepmd/pd/utils/dataloader.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pd/utils/dataloader.py#L264-L265

Added lines #L264 - L265 were not covered by tests
else:
self._queue.put(StopIteration())


class BufferedIterator:
Expand Down
12 changes: 7 additions & 5 deletions deepmd/pt/utils/dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,13 @@
self._source = source # Main DL iterator

def run(self) -> None:
for item in self._source:
self._queue.put(item) # Blocking if the queue is full

# Signal the consumer we are done; this should not happen for DataLoader
self._queue.put(StopIteration())
try:
for item in self._source:
self._queue.put(item) # Blocking if the queue is full
except Exception as e:
self._queue.put(e)

Check warning on line 225 in deepmd/pt/utils/dataloader.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/utils/dataloader.py#L224-L225

Added lines #L224 - L225 were not covered by tests
Comment on lines +224 to +225
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the exception is not covered by ut. And what possible exception will be raised instead of StopIteration here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of the pytorch dataloader throws unexpected exceptions. Generally this code path is not used.

else:
self._queue.put(StopIteration())


QUEUESIZE = 32
Expand Down