-
-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
tempfile.TemporaryDirectory fails to delete itself #74168
Comments
There's a known issue with The issue is well known (https://mail.python.org/pipermail/python-dev/2013-September/128353.html), and the agreement is that it cannot be cleanly solved inside However, what to do about I don't think So perhaps the retry loop should be added to |
A simpler approach would be to simply ignore the error when it occurs in TemporaryDirectory._cleanup. There are no absolute guarantees about tempfile always cleaning up -- just a best effort. The complexity (and potential delays) of a retry loop seem more risky than simply occasionally not cleaning up -- that happens anyways, for a variety of reasons. |
In addition to transient failures, this can also occur when, for example, files opened in the temporary directory (perhaps by library or application code not under direct control of the caller) haven't been properly cleaned up and their file handles don't get closed, resulting in permissions errors trying to delete them (particularly on platforms like Windows, that automatically lock files when opening them). This case came up in e.g. this recent PR and rendered Therefore, in the spirit of Guido's statements above in terms of providing a "best-effort" cleanup, I propose (and am willing to submit a PR to implement) adding an Would a PR be accepted on this? If so, any specific guidance on tests and whether to mention it in What's New, etc., would be appreciated. Thanks! |
SGTM |
On CircleCI, Windows unittests are failing for Python 3.7 with `PermissionError` at the end of test when it cleans up temporary directory. According to the discussion python/cpython#74168, this is caused by a known issue with `shutil.rmtree`. In the above thread it is advised to simply ignore the error as it is not guaranteed that temp directories are cleaned up. This commit follows the same path and simply ignore the error so that our CI gets back to green.
On CircleCI, Windows unittests are failing for Python 3.7 with `PermissionError` at the end of test when it cleans up temporary directory. According to the discussion python/cpython#74168, this is caused by a known issue with `shutil.rmtree`. In the above thread it is advised to simply ignore the error as it is not guaranteed that temp directories are cleaned up. This commit follows the same path and simply ignore the error so that our CI gets back to green.
Summary: On CircleCI, Windows unittests are failing for Python 3.7 with `PermissionError` at the end of test when it cleans up temporary directory. According to the discussion python/cpython#74168, this is caused by a known issue with `shutil.rmtree`. In the above thread it is advised to simply ignore the error as it is not guaranteed that temp directories are cleaned up. This commit follows the same path and simply ignore the error so that our CI gets back to green. Pull Request resolved: #2379 Reviewed By: carolineechen Differential Revision: D36305595 Pulled By: mthrok fbshipit-source-id: d9049c2ee3447712119786311f639a1f9f8911c5
Workaround for python/cpython#74168
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: