"""nodoctest1"""23###############################################################################4# Sage: System for Algebra and Geometry Experimentation5# Copyright (C) 2007 William Stein <[email protected]>6# Distributed under the terms of the GNU General Public License (GPL)7# The full text of the GPL is available at:8# http://www.gnu.org/licenses/9###############################################################################10# Triva Note: For the name "sage-cleaner", think of the11# "The Cleaner" from Pulp Fiction:12# http://www.frankjankowski.de/quiz/illus/keitel.jpg13###############################################################################14import os1516import sage.misc.misc as misc17F = '%s/spawned_processes'%misc.SAGE_TMP1819def cleaner(pid, cmd=''):20if cmd != '':21cmd = cmd.strip().split()[0]22# This is safe, since only this process writes to this file.23if os.path.exists(F):24o = open(F,'a')25else:26if not os.path.exists(misc.SAGE_TMP):27return28o = open(F,'w')29o.write('%s %s\n'%(pid, cmd))30o.close()31start_cleaner_if_not_running()3233################3435def start_cleaner_if_not_running():36D = '%s/tmp_cleaner.pid'%misc.DOT_SAGE37try:38pid = int(open(D).read())39os.kill(pid,0)40return41except (IOError, OSError, ValueError):42os.system('sage-cleaner >/dev/null 2>/dev/null &') # it has died434445464748