Simply exit DataLoader when Python is dying#12700
Closed
ssnl wants to merge 3 commits intopytorch:masterfrom
Closed
Simply exit DataLoader when Python is dying#12700ssnl wants to merge 3 commits intopytorch:masterfrom
ssnl wants to merge 3 commits intopytorch:masterfrom
Conversation
Collaborator
Author
|
Also, the general recommendation is to never use |
ssnl
commented
Oct 16, 2018
| # | ||
| # 2. The iterator exits the workers when the loader process and/or worker | ||
| # processes exits unexpectedly (e.g., SIGKILL-ed). | ||
| # processes exits normally or with error. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
ezyang
approved these changes
Oct 17, 2018
Contributor
ezyang
left a comment
There was a problem hiding this comment.
Thanks, love the commentary.
Collaborator
Author
|
last commit is only comment change and build passed on previous commit so I'm landing. |
Contributor
facebook-github-bot
left a comment
There was a problem hiding this comment.
SsnL is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
laurentdupin
pushed a commit
to laurentdupin/pytorch
that referenced
this pull request
Apr 24, 2026
Summary: I struggled with yet another DataLoader hang for the entire evening. After numerous experiments, I realized that it is unsafe to do anything when Python is shutting down. We also unfortunately implement our DataLaoder cleaning-up logic in `__del__`, a function that may or may not be called during shutdown, and if called, may or may not be called before core library resources are freed. Fortunately, we are already setting all our workers and pin_memory_thread as daemonic. So in case of Python shutting down, we can just do a no-op in `__del__` and rely on the automatic termination of daemonic children. An `atexit` hook is used to detect Python exit. Pull Request resolved: pytorch#12700 Differential Revision: D10419027 Pulled By: SsnL fbshipit-source-id: 5753e70d03e69eb1c9ec4ae2154252d51e2f79b0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I struggled with yet another DataLoader hang for the entire evening. After numerous experiments, I realized that it is unsafe to do anything when Python is shutting down. We also unfortunately implement our DataLaoder cleaning-up logic in
__del__, a function that may or may not be called during shutdown, and if called, may or may not be called before core library resources are freed.Fortunately, we are already setting all our workers and pin_memory_thread as daemonic. So in case of Python shutting down, we can just do a no-op in
__del__and rely on the automatic termination of daemonic children.An
atexithook is used to detect Python exit.