Ignore errors when deleting files and folders on Windows#3289
Ignore errors when deleting files and folders on Windows#3289pkch wants to merge 3 commits intopython:masterfrom
Conversation
gvanrossum
left a comment
There was a problem hiding this comment.
I'd prefer not to add a dependency on the mypy package to files in misc. Haven't seen the rest in detail yet.
|
(The rest LGTM.) |
misc/util.py
Outdated
| @@ -0,0 +1,9 @@ | |||
| import os | |||
There was a problem hiding this comment.
Please just restore the original code. This folder is not a package, and I really don't want a toplevel module named 'util'. (And there are many good reasons why the folder should not be made into a package.)
There was a problem hiding this comment.
Ahh right I didn't notice util.py would become a top-level module..
|
I'm still at most lukewarm about this, since I've never heard any reports of errors due to os.remove() or shutil.rmtree(). |
|
Confirmed, I don't see any AppVeyor test failures due to this. I did have local test failures, however I'd be perfectly fine to just ignore them. So we can close this until we see any failures due to delete. |
|
OK, let's close for now. Thanks for thinking about the issue! |
This, in combination #3288, removes all known Windows test errors due to failed deletes (note: this PR has no overlap with #3288 and the closed #3239 ).
The change in this PR affects primarily Windows - by catching
OSErrorwhen deletion fails.In couple of cases, it also affects Linux in the sense that it checks whether a folder is present before attempting to
shutil.rmtreeit, and catches errors when attempting to cleanup aTemporaryDirectory. However, in the specific contexts where it happens, this change is harmless.One potential issue is not solved in this PR, but it is not present in our codebase at the moment, and we should avoid introducing it anyway, so there's nothing to worry about. Still, just for reference in case this comes up:
TemporaryDirectory, in its finalizer, deletes the temporary folder without catchingOSError(the finalizer is called from gc and fromatexit). Ifcleanup()is called explicitly, the finalizer is detached, and that's what we do (and should continue to do) in our codebase (of course, I putcleanup()call inside try/except). However, if aTemporaryDirectoryis accidentally allowed to go out of scope or survive till interpreter exit without acleanup()call, the finalizer will kick in, and on Windows might raise an exception (if called fromatexit) or print stuff tostderr(if called from gc). If we did want to fix this, we could simply wrapTemporaryDirectoryin our own class that has its own finalizer that callscleanup()of the wrappedTemporaryDirectoryinstance. The finalizer semantics would ensure that our own finalizer is called first (since gc can't touch the wrapped object while there are references to it, andatexitwill call our finalizer first as it was created later). As I said though, this is unnecessary since we always explicitly callcleanup().