当前位置: 首页>>代码示例>>Python>>正文


Python weakref.getweakrefcount方法代码示例

本文整理汇总了Python中weakref.getweakrefcount方法的典型用法代码示例。如果您正苦于以下问题:Python weakref.getweakrefcount方法的具体用法?Python weakref.getweakrefcount怎么用?Python weakref.getweakrefcount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在weakref的用法示例。


在下文中一共展示了weakref.getweakrefcount方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_ref_reuse

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import getweakrefcount [as 别名]
def test_ref_reuse(self):
        o = C()
        ref1 = weakref.ref(o)
        # create a proxy to make sure that there's an intervening creation
        # between these two; it should make no difference
        proxy = weakref.proxy(o)
        ref2 = weakref.ref(o)
        self.assertIs(ref1, ref2,
                     "reference object w/out callback should be re-used")

        o = C()
        proxy = weakref.proxy(o)
        ref1 = weakref.ref(o)
        ref2 = weakref.ref(o)
        self.assertIs(ref1, ref2,
                     "reference object w/out callback should be re-used")
        self.assertEqual(weakref.getweakrefcount(o), 2,
                     "wrong weak ref count for object")
        del proxy
        self.assertEqual(weakref.getweakrefcount(o), 1,
                     "wrong weak ref count for object after deleting proxy") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:23,代码来源:test_weakref.py

示例2: test_getweakrefcount

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import getweakrefcount [as 别名]
def test_getweakrefcount(self):
        o = C()
        ref1 = weakref.ref(o)
        ref2 = weakref.ref(o, self.callback)
        self.assertEqual(weakref.getweakrefcount(o), 2,
                     "got wrong number of weak reference objects")

        proxy1 = weakref.proxy(o)
        proxy2 = weakref.proxy(o, self.callback)
        self.assertEqual(weakref.getweakrefcount(o), 4,
                     "got wrong number of weak reference objects")

        del ref1, ref2, proxy1, proxy2
        self.assertEqual(weakref.getweakrefcount(o), 0,
                     "weak reference objects not unlinked from"
                     " referent when discarded.")

        # assumes ints do not support weakrefs
        self.assertEqual(weakref.getweakrefcount(1), 0,
                     "got wrong number of weak reference objects for int") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:test_weakref.py

示例3: test_subclass_refs_dont_replace_standard_refs

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import getweakrefcount [as 别名]
def test_subclass_refs_dont_replace_standard_refs(self):
        class MyRef(weakref.ref):
            pass
        o = Object(42)
        r1 = MyRef(o)
        r2 = weakref.ref(o)
        self.assertIsNot(r1, r2)
        self.assertEqual(weakref.getweakrefs(o), [r2, r1])
        self.assertEqual(weakref.getweakrefcount(o), 2)
        r3 = MyRef(o)
        self.assertEqual(weakref.getweakrefcount(o), 3)
        refs = weakref.getweakrefs(o)
        self.assertEqual(len(refs), 3)
        self.assertIs(r2, refs[0])
        self.assertIn(r1, refs[1:])
        self.assertIn(r3, refs[1:]) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_weakref.py

示例4: test_ref_reuse

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import getweakrefcount [as 别名]
def test_ref_reuse(self):
        o = C()
        ref1 = weakref.ref(o)
        # create a proxy to make sure that there's an intervening creation
        # between these two; it should make no difference
        proxy = weakref.proxy(o)
        ref2 = weakref.ref(o)
        self.assertTrue(ref1 is ref2,
                     "reference object w/out callback should be re-used")

        o = C()
        proxy = weakref.proxy(o)
        ref1 = weakref.ref(o)
        ref2 = weakref.ref(o)
        self.assertTrue(ref1 is ref2,
                     "reference object w/out callback should be re-used")
        self.assertTrue(weakref.getweakrefcount(o) == 2,
                     "wrong weak ref count for object")
        del proxy
        self.assertTrue(weakref.getweakrefcount(o) == 1,
                     "wrong weak ref count for object after deleting proxy") 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:23,代码来源:test_weakref.py

示例5: test_getweakrefcount

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import getweakrefcount [as 别名]
def test_getweakrefcount(self):
        o = C()
        ref1 = weakref.ref(o)
        ref2 = weakref.ref(o, self.callback)
        self.assertTrue(weakref.getweakrefcount(o) == 2,
                     "got wrong number of weak reference objects")

        proxy1 = weakref.proxy(o)
        proxy2 = weakref.proxy(o, self.callback)
        self.assertTrue(weakref.getweakrefcount(o) == 4,
                     "got wrong number of weak reference objects")

        del ref1, ref2, proxy1, proxy2
        self.assertTrue(weakref.getweakrefcount(o) == 0,
                     "weak reference objects not unlinked from"
                     " referent when discarded.")

        # assumes ints do not support weakrefs
        self.assertTrue(weakref.getweakrefcount(1) == 0,
                     "got wrong number of weak reference objects for int") 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:22,代码来源:test_weakref.py

示例6: test_subclass_refs_dont_replace_standard_refs

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import getweakrefcount [as 别名]
def test_subclass_refs_dont_replace_standard_refs(self):
        class MyRef(weakref.ref):
            pass
        o = Object(42)
        r1 = MyRef(o)
        r2 = weakref.ref(o)
        self.assertTrue(r1 is not r2)
        self.assertEqual(weakref.getweakrefs(o), [r2, r1])
        self.assertEqual(weakref.getweakrefcount(o), 2)
        r3 = MyRef(o)
        self.assertEqual(weakref.getweakrefcount(o), 3)
        refs = weakref.getweakrefs(o)
        self.assertEqual(len(refs), 3)
        self.assertTrue(r2 is refs[0])
        self.assertIn(r1, refs[1:])
        self.assertIn(r3, refs[1:]) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:18,代码来源:test_weakref.py

示例7: test_ref_reuse

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import getweakrefcount [as 别名]
def test_ref_reuse(self):
        o = C()
        ref1 = weakref.ref(o)
        # create a proxy to make sure that there's an intervening creation
        # between these two; it should make no difference
        proxy = weakref.proxy(o)
        ref2 = weakref.ref(o)
        self.assert_(ref1 is ref2,
                     "reference object w/out callback should be re-used")

        o = C()
        proxy = weakref.proxy(o)
        ref1 = weakref.ref(o)
        ref2 = weakref.ref(o)
        self.assert_(ref1 is ref2,
                     "reference object w/out callback should be re-used")
        self.assert_(weakref.getweakrefcount(o) == 2,
                     "wrong weak ref count for object")
        del proxy
        extra_collect()
        self.assert_(weakref.getweakrefcount(o) == 1,
                     "wrong weak ref count for object after deleting proxy") 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:24,代码来源:test_weakref.py

示例8: test_getweakrefcount

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import getweakrefcount [as 别名]
def test_getweakrefcount(self):
        o = C()
        ref1 = weakref.ref(o)
        ref2 = weakref.ref(o, self.callback)
        self.assert_(weakref.getweakrefcount(o) == 2,
                     "got wrong number of weak reference objects")

        proxy1 = weakref.proxy(o)
        proxy2 = weakref.proxy(o, self.callback)
        self.assert_(weakref.getweakrefcount(o) == 4,
                     "got wrong number of weak reference objects")

        del ref1, ref2, proxy1, proxy2
        extra_collect()
        self.assert_(weakref.getweakrefcount(o) == 0,
                     "weak reference objects not unlinked from"
                     " referent when discarded.")

        # assumes ints do not support weakrefs
        self.assert_(weakref.getweakrefcount(1) == 0,
                     "got wrong number of weak reference objects for int") 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:23,代码来源:test_weakref.py

示例9: test_subclass_refs_dont_replace_standard_refs

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import getweakrefcount [as 别名]
def test_subclass_refs_dont_replace_standard_refs(self):
        class MyRef(weakref.ref):
            pass
        o = Object(42)
        r1 = MyRef(o)
        r2 = weakref.ref(o)
        self.assert_(r1 is not r2)
        self.assertEqual(weakref.getweakrefs(o), [r2, r1])
        self.assertEqual(weakref.getweakrefcount(o), 2)
        r3 = MyRef(o)
        self.assertEqual(weakref.getweakrefcount(o), 3)
        refs = weakref.getweakrefs(o)
        self.assertEqual(len(refs), 3)
        self.assert_(r2 is refs[0])
        self.assert_(r1 in refs[1:])
        self.assert_(r3 in refs[1:]) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:18,代码来源:test_weakref.py

示例10: test_ref_reuse

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import getweakrefcount [as 别名]
def test_ref_reuse(self):
        o = C()
        ref1 = weakref.ref(o)
        # create a proxy to make sure that there's an intervening creation
        # between these two; it should make no difference
        proxy = weakref.proxy(o)
        ref2 = weakref.ref(o)
        self.assertTrue(ref1 is ref2,
                     "reference object w/out callback should be re-used")

        o = C()
        proxy = weakref.proxy(o)
        ref1 = weakref.ref(o)
        ref2 = weakref.ref(o)
        self.assertTrue(ref1 is ref2,
                     "reference object w/out callback should be re-used")
        self.assertTrue(weakref.getweakrefcount(o) == 2,
                     "wrong weak ref count for object")
        del proxy
        gc.collect()
        self.assertTrue(weakref.getweakrefcount(o) == 1,
                     "wrong weak ref count for object after deleting proxy") 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:24,代码来源:test_weakref.py

示例11: test_getweakrefcount

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import getweakrefcount [as 别名]
def test_getweakrefcount(self):
        o = C()
        ref1 = weakref.ref(o)
        ref2 = weakref.ref(o, self.callback)
        self.assertTrue(weakref.getweakrefcount(o) == 2,
                     "got wrong number of weak reference objects")

        proxy1 = weakref.proxy(o)
        proxy2 = weakref.proxy(o, self.callback)
        self.assertTrue(weakref.getweakrefcount(o) == 4,
                     "got wrong number of weak reference objects")

        del ref1, ref2, proxy1, proxy2
        gc.collect()
        self.assertTrue(weakref.getweakrefcount(o) == 0,
                     "weak reference objects not unlinked from"
                     " referent when discarded.")

        # assumes ints do not support weakrefs
        self.assertTrue(weakref.getweakrefcount(1) == 0,
                     "got wrong number of weak reference objects for int") 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:23,代码来源:test_weakref.py

示例12: test_subclass_refs_dont_replace_standard_refs

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import getweakrefcount [as 别名]
def test_subclass_refs_dont_replace_standard_refs(self):
        class MyRef(weakref.ref):
            pass
        o = Object(42)
        r1 = MyRef(o)
        r2 = weakref.ref(o)
        self.assertTrue(r1 is not r2)
        self.assertEqual(weakref.getweakrefs(o), [r2, r1])
        self.assertEqual(weakref.getweakrefcount(o), 2)
        r3 = MyRef(o)
        self.assertEqual(weakref.getweakrefcount(o), 3)
        refs = weakref.getweakrefs(o)
        self.assertEqual(len(refs), 3)
        self.assertIn(r1, refs)
        self.assertIn(r2, refs)
        self.assertIn(r3, refs) 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:18,代码来源:test_weakref.py


注:本文中的weakref.getweakrefcount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。