Skip to content

Commit 77e6e4e

Browse files
authored
Fix Windows tempdir cleanup race in test_vrt_tiled_scheduler_1714 (#1748)
Threaded dask writes can leave file handles briefly open after the context manager exits, so Windows raises PermissionError [WinError 32] on the recursive directory removal. Linux closes the handles before shutil.rmtree walks the tree, so it never fails there. Pass ignore_cleanup_errors=True on each TemporaryDirectory. The tests verify the writes succeeded before the context exits, so the cleanup failure is purely a Windows-side temp-file leak, not a real bug.
1 parent 8adb749 commit 77e6e4e

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

xrspatial/geotiff/tests/test_vrt_tiled_scheduler_1714.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ def _make_dask_da(h: int = 32, w: int = 32, chunk: int = 8) -> xr.DataArray:
4141
def test_vrt_tiled_uses_threaded_scheduler():
4242
"""_write_vrt_tiled passes ``scheduler='threads'`` to dask.compute."""
4343
da_arr = _make_dask_da()
44-
with tempfile.TemporaryDirectory(prefix="vrt_sched_1714_") as td:
44+
with tempfile.TemporaryDirectory(
45+
prefix="vrt_sched_1714_", ignore_cleanup_errors=True
46+
) as td:
4547
vrt = os.path.join(td, "sched_check.vrt")
4648

4749
# Wrap dask.compute so we can record the scheduler kwarg the
@@ -67,7 +69,9 @@ def spy(*args, **kwargs):
6769
def test_vrt_tiled_threaded_write_produces_all_tiles():
6870
"""All expected tile files exist after the threaded write."""
6971
da_arr = _make_dask_da(h=32, w=32, chunk=8) # 4x4 = 16 tiles
70-
with tempfile.TemporaryDirectory(prefix="vrt_sched_1714_") as td:
72+
with tempfile.TemporaryDirectory(
73+
prefix="vrt_sched_1714_", ignore_cleanup_errors=True
74+
) as td:
7175
vrt = os.path.join(td, "tile_count.vrt")
7276
to_geotiff(da_arr, vrt)
7377
tiles_dir = os.path.join(td, "tile_count_tiles")
@@ -95,8 +99,12 @@ def _write_and_collect(vrt_path: str) -> dict[str, bytes]:
9599
for p in sorted(glob.glob(os.path.join(tiles_dir, "*.tif")))
96100
}
97101

98-
with tempfile.TemporaryDirectory(prefix="vrt_sched_1714_") as td1:
99-
with tempfile.TemporaryDirectory(prefix="vrt_sched_1714_") as td2:
102+
with tempfile.TemporaryDirectory(
103+
prefix="vrt_sched_1714_", ignore_cleanup_errors=True
104+
) as td1:
105+
with tempfile.TemporaryDirectory(
106+
prefix="vrt_sched_1714_", ignore_cleanup_errors=True
107+
) as td2:
100108
tiles1 = _write_and_collect(os.path.join(td1, "run1.vrt"))
101109
tiles2 = _write_and_collect(os.path.join(td2, "run2.vrt"))
102110

0 commit comments

Comments
 (0)