Skip to content

Conversation

@ejguan
Copy link
Contributor

@ejguan ejguan commented Nov 30, 2022

There is a case that file.close is never called because when generator function has never reached to the end. A simple example would be zip two datepipes with different length. The longer DataPipe would never reach the end of generator and then it will be cleaned up by gc. So, the line of file.close is not executed. (This is the reason that Vitaly has to create this hack to retrieve all remaining data to make sure generator function is fully executed)

However, this hack introduces another problem where an infinite datapipe would make zip never end as it would try to deplete the infinite iterator. See: #865

So, in this PR, I am adding a try-finally clause to make sure the file.close is always executed during the destruction of generator object. Then, we don't need the hack within zip any more.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 30, 2022
@ejguan ejguan requested a review from NivekT November 30, 2022 23:06
@facebook-github-bot
Copy link
Contributor

@ejguan has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Contributor

@NivekT NivekT left a comment

Choose a reason for hiding this comment

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

Just one question on this, but overall, this LGTM!

Will look at the rest soon

Copy link
Contributor

@wenleix wenleix left a comment

Choose a reason for hiding this comment

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

Thanks!

@facebook-github-bot
Copy link
Contributor

@ejguan has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@ejguan ejguan changed the title [1/4] Properly cleanup unclosed files within generator function [2/4] Properly cleanup unclosed files within generator function Dec 1, 2022
@ejguan ejguan changed the title [2/4] Properly cleanup unclosed files within generator function [3/4] Properly cleanup unclosed files within generator function Dec 1, 2022
@ejguan ejguan added the topic: bug fixes topic category label Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. topic: bug fixes topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants