Skip to content

Commit

Permalink
Fix spyx_tmp() cleanup.
Browse files Browse the repository at this point in the history
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] python/cpython#114279
[1] sagemath#39188 (comment)
[2] sagemath#39188 (comment)
  • Loading branch information
tornaria committed Dec 24, 2024
1 parent 8a972c4 commit 54fc1e6
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/sage/misc/temporary_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 54fc1e6

Please sign in to comment.