test_watchdog.py 文件源码

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

项目:landscape-client 作者: CanonicalLtd 项目源码 文件源码
def test_kill_process_with_sigkill(self):
        """
        Verify that killing process really works, even if something is
        holding the process badly.  In these cases, a SIGKILL is performed
        some time after the SIGTERM was issued and didn't work.
        """
        output_filename = self.makeFile("NOT RUN")
        self._write_script(
            ("#!%s\n"
             "import signal, os\n"
             "signal.signal(signal.SIGTERM, signal.SIG_IGN)\n"
             "file = open(%r, 'w')\n"
             "file.write('RUN')\n"
             "file.close()\n"
             "os.kill(os.getpid(), signal.SIGSTOP)\n"
             ) % (sys.executable, output_filename))

        self.addCleanup(setattr, landscape.client.watchdog, "SIGKILL_DELAY",
                        landscape.client.watchdog.SIGKILL_DELAY)
        landscape.client.watchdog.SIGKILL_DELAY = 1

        waiter = FileChangeWaiter(output_filename)
        self.daemon.start()
        waiter.wait()
        self.assertEqual(open(output_filename).read(), "RUN")
        return self.daemon.stop()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号