From 54fc1e6144d67b77b9ec0d9fcd76dfe66a5d0827 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Tornar=C3=ADa?= Date: Tue, 24 Dec 2024 18:27:38 -0300 Subject: [PATCH] Fix `spyx_tmp()` cleanup. For some reason, a new behaviour of python 3.13 [0] causes the `TemporaryDirectory()` in `sage.misc.temporary_file.spyx_tmp()` to be deleted on child exit, which causes trouble with parallel doctesting [1]. We rewrite `spyx_tmp()` using `tmp_dir()`, which doesn't have this problem, see [2]. [0] https://github.com/python/cpython/pull/114279 [1] https://github.com/sagemath/sage/pull/39188#issuecomment-2559925083 [2] https://github.com/sagemath/sage/pull/39188#issuecomment-2561459269 --- src/sage/misc/temporary_file.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/sage/misc/temporary_file.py b/src/sage/misc/temporary_file.py index 998260be8eb..9b88b826354 100644 --- a/src/sage/misc/temporary_file.py +++ b/src/sage/misc/temporary_file.py @@ -533,14 +533,11 @@ def spyx_tmp() -> str: We cache the result of this function "by hand" so that the same temporary directory will always be returned. A function is used to delay creating a directory until (if) it is needed. The temporary - directory is removed when sage terminates by way of an atexit - hook. + directory is automatically removed when sage terminates. """ global _spyx_tmp if _spyx_tmp: return _spyx_tmp - d = tempfile.TemporaryDirectory() - _spyx_tmp = os.path.join(d.name, 'spyx') - atexit.register(lambda: d.cleanup()) + _spyx_tmp = tmp_dir(name='spyx_') return _spyx_tmp