This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author CAM-Gerlach
Recipients CAM-Gerlach, Jeffrey.Kintscher, gvanrossum, max, paul.moore, serhiy.storchaka, steve.dower, tim.golden, zach.ware
Date 2021-03-07.03:09:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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 `tempfile.TemporaryDirectory` unusable for such use cases, forcing a reversion to the lower-level `tempfile.mkdtemp` without the cleaner, more robust and easier to interpret high-level interface that the former provides. Wrapping a `with` statement in a try-finally is syntactically ugly and semantically incongruous, and requires a second shutil.rmtree(..., ignore_errors=True)` call to clean up in a best-effort manner, while when manually calling `cleanup()` in a try-except, the finalizer still gets executed at a a non-deterministic later time when Python exits, raising an error.

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 `ignore_errors` bool parameter (defaulting to False, of course, for backward compat--and should it be keyword only like `errors` to `TemporaryFile`?) to the `tempfile.TemporaryDirectory` constructor, which gets  passed to `shutil.rmtree` on cleanup. This would not only address both cases here, but also one of the two discussed by Anthony Sotitle on [BPO-25024](, in a cleaner and simpler fashion that would take advantage of existing `tempfile.TemporaryDirectory` functionality and behavior.

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!
Date User Action Args
2021-03-07 03:09:48CAM-Gerlachsetrecipients: + CAM-Gerlach, gvanrossum, paul.moore, tim.golden, max, zach.ware, serhiy.storchaka, steve.dower, Jeffrey.Kintscher
2021-03-07 03:09:48CAM-Gerlachsetmessageid: <>
2021-03-07 03:09:48CAM-Gerlachlinkissue29982 messages
2021-03-07 03:09:44CAM-Gerlachcreate