gh-81483: Add an "onerror" callback parameter to the tempfile.TemporaryDirectory member functions#14292
gh-81483: Add an "onerror" callback parameter to the tempfile.TemporaryDirectory member functions#14292websurfer5 wants to merge 5 commits intopython:mainfrom
Conversation
iritkatriel
left a comment
There was a problem hiding this comment.
See recent changes to rmtree's onerror arg: #102829
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
|
@websurfer5 could you please resolve the conflicts and update the PR? |
|
The feature request was rejected by @giampaolo in #80603 (comment). Closing. |


This PR adds an "onerror" callback parameter to the tempfile.TemporaryDirectory() member functions so that the caller can perform special handling for directory items that it can't automatically delete. The caller created the undeletable directory entries, so it is reasonable to believe the caller may know how to unmake what they made.
The provided test cases create a filesystem image and mount it within the temporary directory to force an error in the underlying shutil.rmtree() call during cleanup that triggers calls to the new onerror parameters. The test cases are provided for macOS because Windows and Linux require special user privileges to create and/or mount/unmount a filesystem image. This method was chosen to simulate the cleanup problems described in bpo-36422.
I am open to suggestions on how to force errors on those systems or in a portable manner. The usual trick of changing directory entry permissions won't work because tempfile.TemporaryDirectory() has heuristics to handle that case.
https://bugs.python.org/issue37302