Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document and manage temporary directories #34593

Closed
jhpalmieri opened this issue Sep 27, 2022 · 18 comments
Closed

Document and manage temporary directories #34593

jhpalmieri opened this issue Sep 27, 2022 · 18 comments

Comments

@jhpalmieri
Copy link
Member

This is a followup to #33213. Some users prefer (or need) to control where temporary files are created, and we should document this:

Possible follow-up:

Component: misc

Author: John Palmieri

Branch/Commit: c729c7b

Reviewer: Matthias Koeppe

Issue created by migration from https://trac.sagemath.org/ticket/34593

@jhpalmieri jhpalmieri added this to the sage-9.8 milestone Sep 27, 2022
@jhpalmieri
Copy link
Member Author

comment:1

Of course I don't know where we should document this, since it's a Python feature which may be used in various components of Sage. I don't know the natural home for it.

@egourgoulhon
Copy link
Member

comment:2

Regarding the ticket title, IMHO the objective should be more "manage" than "document" since 3D plots are badly broken in Sage 9.7 for (at least) Ubuntu 22.04 users with the default settings, as revealed by https://ask.sagemath.org/question/64192/temporary-html-files-location-in-sage-97/

@jhpalmieri
Copy link
Member Author

comment:4

Should Sage itself set the environment variable TMPDIR? (If the user hasn't set it, I mean.)

@egourgoulhon
Copy link
Member

comment:5

Replying to John Palmieri:

Should Sage itself set the environment variable TMPDIR? (If the user hasn't set it, I mean.)

This could a solution, for instance defining TMPDIR to be a subdirectory of DOT_SAGE. But there may be some undesirable effects, e.g. for Sage running on servers or SageMathCell. Also would it be desirable/doable to clean that directory when the Sage session ends?

@jhpalmieri

This comment has been minimized.

@dimpase
Copy link
Member

dimpase commented Oct 13, 2022

comment:7

Replying to Eric Gourgoulhon:

Replying to John Palmieri:

Should Sage itself set the environment variable TMPDIR? (If the user hasn't set it, I mean.)

This could a solution, for instance defining TMPDIR to be a subdirectory of DOT_SAGE. But there may be some undesirable effects, e.g. for Sage running on servers or SageMathCell. Also would it be desirable/doable to clean that directory when the Sage session ends?

I beleive that the cleanup is automatic, using Python's atexit callback.
https://docs.python.org/3/library/atexit.html

(there is of course always a chance of a segfault-like abnormal exit, which might leave
rubbish after itself:

The functions registered via this module are not called when the program is killed
by a signal not handled by Python, when a Python fatal internal error is detected,
or when os._exit() is called.

This is what we have in src/misc/temporary_file.py:

import tempfile

import atexit

# Until tmp_dir() and tmp_filename() are removed, we use this directory
# as the parent for all temporary files & directories created by them.
# This lets us clean up after those two functions when sage exits normally
# using an atexit hook
TMP_DIR_FILENAME_BASE=tempfile.TemporaryDirectory()
atexit.register(lambda: TMP_DIR_FILENAME_BASE.cleanup())

@dimpase
Copy link
Member

dimpase commented Oct 13, 2022

comment:8

In an environment such as SageMathCell, I think one user runs many Sage instances, so one cannot clean anything on startup without risking to affect other instances.

@mkoeppe
Copy link
Member

mkoeppe commented Nov 21, 2022

comment:9

Let's move the documentation of runtime environment variables, starting at "Sage uses the following environment variables when it runs:" https://doc.sagemath.org/html/en/installation/source.html to the "Launching section" and add TMPDIR there (perhaps pointer to Python runtime environment variables)

@jhpalmieri
Copy link
Member Author

@jhpalmieri
Copy link
Member Author

comment:11

And also jupyter/notebook#4500.

@jhpalmieri
Copy link
Member Author

Branch: u/jhpalmieri/document-TMPDIR

@jhpalmieri
Copy link
Member Author

Author: John Palmieri

@jhpalmieri
Copy link
Member Author

comment:13

Here is an addition to the documentation.


New commits:

c729c7btrac 34593: document the variable TMPDIR.

@jhpalmieri
Copy link
Member Author

Commit: c729c7b

@mkoeppe
Copy link
Member

mkoeppe commented Nov 24, 2022

Reviewer: Matthias Koeppe

@mkoeppe

This comment has been minimized.

@jhpalmieri
Copy link
Member Author

comment:15

Thank you!

@vbraun
Copy link
Member

vbraun commented Dec 11, 2022

Changed branch from u/jhpalmieri/document-TMPDIR to c729c7b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants