test_threading.py 文件源码

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

项目:zippy 作者: securesystemslab 项目源码 文件源码
def test_enumerate_after_join(self):
        # Try hard to trigger #1703448: a thread is still returned in
        # threading.enumerate() after it has been join()ed.
        enum = threading.enumerate
        newgil = hasattr(sys, 'getswitchinterval')
        if newgil:
            geti, seti = sys.getswitchinterval, sys.setswitchinterval
        else:
            geti, seti = sys.getcheckinterval, sys.setcheckinterval
        old_interval = geti()
        try:
            for i in range(1, 100):
                seti(i * 0.0002 if newgil else i // 5)
                t = threading.Thread(target=lambda: None)
                t.start()
                t.join()
                l = enum()
                self.assertNotIn(t, l,
                    "#1703448 triggered after %d trials: %s" % (i, l))
        finally:
            seti(old_interval)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号