From 650428be73bd574e5b3a9a1494b543bd5f39c104 Mon Sep 17 00:00:00 2001 From: Pavel Chekin Date: Mon, 16 Dec 2024 22:39:04 -0800 Subject: [PATCH] Ignore cleanup errors in cache teardown. (#3020) To avoid PermissionError on Windows where certain .pyd files are locked by current Python process and cannot be deleted. Fixes #3019. --- python/test/regression/conftest.py | 16 ++++++++++------ python/test/unit/conftest.py | 16 ++++++++++------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/python/test/regression/conftest.py b/python/test/regression/conftest.py index d88687b45f..23b32aacbd 100644 --- a/python/test/regression/conftest.py +++ b/python/test/regression/conftest.py @@ -14,9 +14,13 @@ def device(request): @pytest.fixture def fresh_triton_cache(): - with tempfile.TemporaryDirectory() as tmpdir: - try: - os.environ["TRITON_CACHE_DIR"] = tmpdir - yield tmpdir - finally: - os.environ.pop("TRITON_CACHE_DIR", None) + try: + with tempfile.TemporaryDirectory() as tmpdir: + try: + os.environ["TRITON_CACHE_DIR"] = tmpdir + yield tmpdir + finally: + os.environ.pop("TRITON_CACHE_DIR", None) + except OSError: + # Ignore errors, such as PermissionError, on Windows + pass diff --git a/python/test/unit/conftest.py b/python/test/unit/conftest.py index d88687b45f..23b32aacbd 100644 --- a/python/test/unit/conftest.py +++ b/python/test/unit/conftest.py @@ -14,9 +14,13 @@ def device(request): @pytest.fixture def fresh_triton_cache(): - with tempfile.TemporaryDirectory() as tmpdir: - try: - os.environ["TRITON_CACHE_DIR"] = tmpdir - yield tmpdir - finally: - os.environ.pop("TRITON_CACHE_DIR", None) + try: + with tempfile.TemporaryDirectory() as tmpdir: + try: + os.environ["TRITON_CACHE_DIR"] = tmpdir + yield tmpdir + finally: + os.environ.pop("TRITON_CACHE_DIR", None) + except OSError: + # Ignore errors, such as PermissionError, on Windows + pass