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

Commit

Permalink
Trac #33213: replace SAGE_TMP in cleaner/quit interfaces.
Browse files Browse the repository at this point in the history
These two modules relied on SAGE_TMP (from sage.misc.misc) to pass
spawned process information back and forth. Now we make
sage.interfaces.cleaner responsible for that path, and use a real
temporary directory for it.
  • Loading branch information
orlitzky committed Feb 17, 2022
1 parent a22fa71 commit 810c855
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/sage/interfaces/cleaner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

import os

from sage.misc.misc import SAGE_TMP
import atexit, tempfile
_spd = tempfile.TemporaryDirectory()
SAGE_SPAWNED_PROCESS_FILE = os.path.join(_spd.name, "spawned_processes")
atexit.register(lambda: _spd.cleanup())

def cleaner(pid, cmd=''):
"""
Expand All @@ -27,9 +30,8 @@ def cleaner(pid, cmd=''):
if cmd != '':
cmd = cmd.strip().split()[0]
# This is safe, since only this process writes to this file.
F = os.path.join(SAGE_TMP, 'spawned_processes')
try:
with open(F, 'a') as o:
with open(SAGE_SPAWNED_PROCESS_FILE, 'a') as o:
o.write('%s %s\n'%(pid, cmd))
except IOError:
pass
Expand Down
8 changes: 4 additions & 4 deletions src/sage/interfaces/quit.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ def kill_spawned_jobs(verbose=False):
sage: sage.interfaces.quit.expect_quitall()
"""
from sage.misc.misc import SAGE_TMP
file = os.path.join(SAGE_TMP, 'spawned_processes')
if not os.path.exists(file):
from sage.interfaces.cleaner import SAGE_SPAWNED_PROCESS_FILE

if not os.path.exists(SAGE_SPAWNED_PROCESS_FILE):
return
with open(file) as f:
with open(SAGE_SPAWNED_PROCESS_FILE) as f:
for L in f:
i = L.find(' ')
pid = L[:i].strip()
Expand Down

0 comments on commit 810c855

Please sign in to comment.