From 6e6fcf4786f75a93584a84cb663b956b1cbbfadc Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Wed, 31 Mar 2021 00:03:21 -0400 Subject: [PATCH] Backport PR #19811: Fix Inkscape cleanup at exit on Windows. --- lib/matplotlib/testing/compare.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/matplotlib/testing/compare.py b/lib/matplotlib/testing/compare.py index fb2e55880cde..afb7edb8c828 100644 --- a/lib/matplotlib/testing/compare.py +++ b/lib/matplotlib/testing/compare.py @@ -13,6 +13,7 @@ import subprocess import sys from tempfile import TemporaryDirectory, TemporaryFile +import weakref import numpy as np from PIL import Image @@ -170,6 +171,9 @@ def __call__(self, orig, dest): terminator = b"\n>" if old_inkscape else b"> " if not hasattr(self, "_tmpdir"): self._tmpdir = TemporaryDirectory() + # On Windows, we must make sure that self._proc has terminated + # (which __del__ does) before clearing _tmpdir. + weakref.finalize(self._tmpdir, self.__del__) if (not self._proc # First run. or self._proc.poll() is not None): # Inkscape terminated. env = {