Stop the daemon

def stop(self):
        """
        Stop the daemon
        """
        # Get the pid from the pidfile
        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  # not an error in a restart
        # Try killing the daemon process
        try:
            while 1:
                #os.kill(pid, SIGTERM)
                os.kill(pid, SIGKILL)
                time.sleep(0.1)
        except OSError, err:
            err = str(err)
            if err.find("No such process") > 0:
                if os.path.exists(self.pidfile):
                    if not self.stdin == '/dev/null':
                        os.remove(self.stdin)

                    if not self.stdout == '/dev/null':
                        os.remove(self.stdout)

                    if not self.stderr == '/dev/null':
                        os.remove(self.stderr)
                        
                    os.remove(self.pidfile)
            else:
                print str(err)
                sys.exit(1)