'Stop the daemon'

def stop(self):

    try:
        pf = file(self.pidfile, 'r')
        pid = int(pf.read().strip())
        pf.close()
    except IOError:
        pid = None
    if (not pid):
        message = 'pidfile    %s    does    not    exist.    Daemon    not    running?\n'
        sys.stderr.write((message % self.pidfile))
        return
    try:
        while 1:
            os.kill(pid, SIGTERM)
            time.sleep(0.1)
    except OSError as err:
        err = str(err)
        if (err.find('No    such    process') > 0):
            self.delpid()
        else:
            sys.exit(1)
