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

Commit fc25b79

Browse files
committed
Trac #33793: cache spyx_tmp() by hand.
This avoids the cython cachefunc dependency, and also happens to disallow easily clearing the cache, which was to be avoided anyway.
1 parent 827c527 commit fc25b79

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/sage/misc/temporary_file.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import io
2727
import os
2828
import tempfile
29-
from sage.misc.cachefunc import cached_function
3029

3130
import atexit
3231

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

549548

550-
@cached_function
549+
_spyx_tmp = None
551550
def spyx_tmp():
552551
r"""
553552
The temporary directory used to store pyx files.
554553
555-
We use a cached function for this so that the same temporary
556-
directory will always be returned (unless the user shoots himself
557-
in the foot). Each temporary directory created is removed when
558-
sage terminates using an atexit hook.
554+
We cache the result of this function "by hand" so that the same
555+
temporary directory will always be returned. A function is used to
556+
delay creating a directory until (if) it is needed. The temporary
557+
directory is removed when sage terminates by way of an atexit
558+
hook.
559559
"""
560+
global _spyx_tmp
561+
if _spyx_tmp:
562+
return _spyx_tmp
563+
560564
d = tempfile.TemporaryDirectory()
561-
result = os.path.join(d.name, 'spyx')
565+
_spyx_tmp = os.path.join(d.name, 'spyx')
562566
atexit.register(lambda: d.cleanup())
563-
return result
567+
return _spyx_tmp

0 commit comments

Comments
 (0)