Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Trac #33793: cache spyx_tmp() by hand.
Browse files Browse the repository at this point in the history
This avoids the cython cachefunc dependency, and also happens to
disallow easily clearing the cache, which was to be avoided anyway.
  • Loading branch information
orlitzky committed May 4, 2022
1 parent 827c527 commit fc25b79
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/sage/misc/temporary_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import io
import os
import tempfile
from sage.misc.cachefunc import cached_function

import atexit

Expand Down Expand Up @@ -547,17 +546,22 @@ def __exit__(self, exc_type, exc_val, exc_tb):
shutil.rmtree(self.tempname)


@cached_function
_spyx_tmp = None
def spyx_tmp():
r"""
The temporary directory used to store pyx files.
We use a cached function for this so that the same temporary
directory will always be returned (unless the user shoots himself
in the foot). Each temporary directory created is removed when
sage terminates using an atexit hook.
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.
"""
global _spyx_tmp
if _spyx_tmp:
return _spyx_tmp

d = tempfile.TemporaryDirectory()
result = os.path.join(d.name, 'spyx')
_spyx_tmp = os.path.join(d.name, 'spyx')
atexit.register(lambda: d.cleanup())
return result
return _spyx_tmp

0 comments on commit fc25b79

Please sign in to comment.