From 5dd174c60b209aff2eef8fa38c12cc8a3c6753db Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Sun, 8 Nov 2020 13:59:28 +0100 Subject: [PATCH] Fix "generator doesn't stop" on Windows When TemporaryDirectory() cleans up on __exit__ it sometimes throws OSError noting that the dir isn't empty. This happens after the first yield in this generator and leads to the exception being handled which leads to a second yield. contextlib.contextmanager() fails then since the function it wraps is only allowed to yield once. Fix this by not yielding again in the error case. Fixes #7947 --- mesonbuild/compilers/compilers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index 6a54622c3..81d48d280 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -785,7 +785,7 @@ class Compiler(metaclass=abc.ABCMeta): # On Windows antivirus programs and the like hold on to files so # they can't be deleted. There's not much to do in this case. Also, # catch OSError because the directory is then no longer empty. - yield None + return @contextlib.contextmanager def cached_compile(self, code: str, cdata: coredata.CoreData, *,