daemon.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:IotCenter 作者: panjanek 项目源码 文件源码
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 # not an error in a restart

        print("killing process with pid {0}".format(pid))
        try:
            while 1:
                os.kill(pid, SIGTERM)
                time.sleep(0.1)
        except OSError, err:
            err = str(err)
            if err.find("No such process") > 0:
                if os.path.exists(self.pidfile):
                    os.remove(self.pidfile)
            else:
                print str(err)
                sys.exit(1)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号