Skip to content

Conversation

@jaraco
Copy link
Member

@jaraco jaraco commented Jul 30, 2021

As reported in python/cpython#27436 (comment), merging the latest importlib_resources into CPython revealed a refleak. It appears the refleak has long been a part of the implementation but was previously uncovered by the tests. This change fixes that refleak.

@jaraco jaraco merged commit 64484b7 into main Jul 30, 2021
@jaraco jaraco deleted the bugfix/as_file-refleak branch July 30, 2021 20:55
@jaraco jaraco restored the bugfix/as_file-refleak branch July 30, 2021 20:55
@jaraco jaraco deleted the bugfix/as_file-refleak branch July 30, 2021 20:55
try:
os.remove(raw_path)
except (FileNotFoundError, PermissionError):
except FileNotFoundError:
Copy link
Member

@FFY00 FFY00 Jul 31, 2021

Choose a reason for hiding this comment

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

Why this part though? IIRC it was added because for some reason Windows will set high permissions on temporary files sometimes.

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe this exception was masking the underlying issue that the file descriptor wasn't being closed. Windows won't allow deletion of files in use, so when we encountered the issue, we suppressed the exception, allowing the file descriptor to remain unclosed and on Windows leaving the file undeleted. Now that the file descriptor is unconditionally closed, there's no longer any need to suppress this exception and as you can see, tests still pass on Windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants