daemon.py 文件源码

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

项目:ank 作者: sunary 项目源码 文件源码
def stop(self):
        """
        Stop the daemon
        """

        if self.verbose >= 1:
            print('Stopping...')

        # Get the pid from the pidfile
        pid = self.get_pid()

        if not pid:
            message = 'pidfile %s does not exist. Not running?\n'
            sys.stderr.write(message % self.pidfile)

            # Just to be sure. A ValueError might occur if the PID file is
            # empty but does actually exist
            if os.path.exists(self.pidfile):
                os.remove(self.pidfile)

            return  # Not an error in a restart

        # Try killing the daemon process
        try:
            i = 0
            while True:
                os.kill(pid, signal.SIGTERM)
                time.sleep(0.1)
                i += 1
                if i % 10 == 0:
                    os.kill(pid, signal.SIGHUP)
        except OSError as 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)

        if self.verbose >= 1:
            print('Stopped')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号