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

Commit

Permalink
Trac #33213: remove sage.interfaces.cleaner.
Browse files Browse the repository at this point in the history
With sage-cleaner gone, it's a bit weird to leave this interface lying
around. Part of it is still used: our expect interface allows
instances to register themselves to be killed with the
expect_quitall() function in sage.interfaces.quit. To keep that
working (for the time being), I've moved/renamed the function that
registers a a process to register_spawned_process() in the module
sage.interfaces.quit.
  • Loading branch information
orlitzky committed Feb 17, 2022
1 parent a9df953 commit 9f504b5
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
1 change: 0 additions & 1 deletion src/doc/en/reference/interfaces/index.rst
Expand Up @@ -108,7 +108,6 @@ and testing to make sure nothing funny is going on).
sage/interfaces/tachyon
sage/interfaces/tides

sage/interfaces/cleaner
sage/interfaces/quit
sage/interfaces/read_data

Expand Down
3 changes: 1 addition & 2 deletions src/sage/interfaces/expect.py
Expand Up @@ -48,7 +48,6 @@
import time
import gc
from . import quit
from . import cleaner
from random import randrange

import pexpect
Expand Down Expand Up @@ -515,7 +514,7 @@ def _start(self, alt_message=None, block_during_init=True):
os.chdir(currentdir)

if self._do_cleaner():
cleaner.cleaner(self._expect.pid, cmd)
quit.register_spawned_process(self._expect.pid, cmd)

try:
self._expect.expect(self._prompt)
Expand Down
4 changes: 2 additions & 2 deletions src/sage/interfaces/qsieve.py
Expand Up @@ -129,7 +129,7 @@ def data_to_list(out, n, time):

from sage.interfaces.sagespawn import SageSpawn
import pexpect
from . import cleaner
from . import quit
class qsieve_nonblock:
"""
A non-blocking version of Hart's quadratic sieve.
Expand Down Expand Up @@ -165,7 +165,7 @@ def __init__(self, n, time):
env = os.environ.copy()
env['TMPDIR'] = tmp_dir('qsieve')
self._p = SageSpawn(cmd, env=env)
cleaner.cleaner(self._p.pid, 'QuadraticSieve')
quit.register_spawned_process(self._p.pid, 'QuadraticSieve')
self._p.sendline(str(self._n)+'\n\n\n')
self._done = False
self._out = ''
Expand Down
23 changes: 20 additions & 3 deletions src/sage/interfaces/quit.py
Expand Up @@ -13,8 +13,27 @@

import os

expect_objects = []
import atexit, tempfile
_spd = tempfile.TemporaryDirectory()
SAGE_SPAWNED_PROCESS_FILE = os.path.join(_spd.name, "spawned_processes")
atexit.register(lambda: _spd.cleanup())

def register_spawned_process(pid, cmd=''):
"""
Write a line to the ``spawned_processes`` file with the given
``pid`` and ``cmd``.
"""
if cmd != '':
cmd = cmd.strip().split()[0]
# This is safe, since only this process writes to this file.
try:
with open(SAGE_SPAWNED_PROCESS_FILE, 'a') as o:
o.write('%s %s\n'%(pid, cmd))
except IOError:
pass


expect_objects = []

def expect_quitall(verbose=False):
"""
Expand Down Expand Up @@ -63,8 +82,6 @@ def kill_spawned_jobs(verbose=False):
sage: sage.interfaces.quit.expect_quitall()
"""
from sage.interfaces.cleaner import SAGE_SPAWNED_PROCESS_FILE

if not os.path.exists(SAGE_SPAWNED_PROCESS_FILE):
return
with open(SAGE_SPAWNED_PROCESS_FILE) as f:
Expand Down
4 changes: 2 additions & 2 deletions src/sage/interfaces/rubik.py
Expand Up @@ -34,7 +34,7 @@

import pexpect
import time
from . import cleaner
from . import quit

from sage.cpython.string import bytes_to_str
from sage.groups.perm_gps.cubegroup import index2singmaster
Expand Down Expand Up @@ -108,7 +108,7 @@ def __init__(self, verbose=False, wait=True):

def start(self):
child = pexpect.spawn(self.__cmd)
cleaner.cleaner(child.pid, self.__cmd)
quit.register_spawned_process(child.pid, self.__cmd)
child.timeout = None
self.child = child
self._ready = False
Expand Down

0 comments on commit 9f504b5

Please sign in to comment.