test_threading.py 文件源码

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

项目:web_ctp 作者: molebot 项目源码 文件源码
def test_is_alive_after_fork(self):
        # Try hard to trigger #18418: is_alive() could sometimes be True on
        # threads that vanished after a fork.
        old_interval = sys.getswitchinterval()
        self.addCleanup(sys.setswitchinterval, old_interval)

        # Make the bug more likely to manifest.
        sys.setswitchinterval(1e-6)

        for i in range(20):
            t = threading.Thread(target=lambda: None)
            t.start()
            self.addCleanup(t.join)
            pid = os.fork()
            if pid == 0:
                os._exit(1 if t.is_alive() else 0)
            else:
                pid, status = os.waitpid(pid, 0)
                self.assertEqual(0, status)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号