• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python weakref.getweakrefs函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_getweakrefs

    def test_getweakrefs(self):
        o = C()
        ref1 = weakref.ref(o, self.callback)
        ref2 = weakref.ref(o, self.callback)
        del ref1
        test_support.gc_collect()
        self.assert_(weakref.getweakrefs(o) == [ref2],
                     "list of refs does not match")

        o = C()
        ref1 = weakref.ref(o, self.callback)
        ref2 = weakref.ref(o, self.callback)
        del ref2
        test_support.gc_collect()
        self.assert_(weakref.getweakrefs(o) == [ref1],
                     "list of refs does not match")

        del ref1
        test_support.gc_collect()
        self.assert_(weakref.getweakrefs(o) == [],
                     "list of refs not cleared")

        # assumes ints do not support weakrefs
        self.assert_(weakref.getweakrefs(1) == [],
                     "list of refs does not match for int")
开发者ID:alkorzt,项目名称:pypy,代码行数:25,代码来源:test_weakref.py


示例2: test_getweakrefs

    def test_getweakrefs(self):
        o = C()
        ref1 = weakref.ref(o, self.callback)
        ref2 = weakref.ref(o, self.callback)
        del ref1
        self.assert_(weakref.getweakrefs(o) == [ref2],
                     "list of refs does not match")

        o = C()
        ref1 = weakref.ref(o, self.callback)
        ref2 = weakref.ref(o, self.callback)
        del ref2
        self.assert_(weakref.getweakrefs(o) == [ref1],
                     "list of refs does not match")
开发者ID:mancoast,项目名称:CPythonPyc_test,代码行数:14,代码来源:212_test_weakref.py


示例3: del_Profile

	def del_Profile(self, profile, del_users=False, no_archive=False, batch=False):
		""" Delete a user profile (LMC.groups is an instance of
			GroupsController and is needed to delete the profile group). """

		assert ltrace(TRACE_PROFILES, '> del_Profile(%s)' % (profile.name))

		# we need to hold the users lock, in case we need to delete users.

		assert ltrace(TRACE_LOCKS, '  del_Profile locks: %s, %s, %s' % (self.lock, LMC.groups.lock, LMC.users.lock))

		with nested(self.lock, LMC.groups.lock, LMC.users.lock):

			# delete the reference in the controller.
			del self[profile.gid]

			# flush the controler data to disk.
			self.serialize()

			if profile.group.is_system_restricted:
				logging.info(_(u'Kept restricted system group %s.') %
															profile.groupName)
			else:
				try:
					LMC.groups.del_Group(profile.group, del_users=del_users,
						no_archive=no_archive, batch=batch,
						# this one is needed to avoid looping...
						check_profiles=False)
				except exceptions.DoesntExistException:
					logging.info('Group %s does not already exist, skipped.' %
															profile.groupName)

			name = profile.name

			assert ltrace(TRACE_GC, '  profile ref count before del: %d %s' % (
				sys.getrefcount(profile), gc.get_referrers(profile)))
			# delete the hopefully last reference to the object. This will
			# delete it from the reverse mapping caches too.
			import weakref
			print weakref.getweakrefs(profile)
			del profile

		# checkpoint, needed for multi-delete (users-groups-profile) operation,
		# to avoid collecting the deleted users at the end of the run, making
		# throw false-negative operation about non-existing groups.
		gc.collect()

		logging.notice(_(u'Deleted profile %s.') % stylize(ST_NAME, name))

		assert ltrace(TRACE_LOCKS, '  del_Profile locks: %s, %s, %s' % (self.lock, LMC.groups.lock, LMC.users.lock))
开发者ID:Licorn,项目名称:licorn,代码行数:49,代码来源:profiles.py


示例4: test_subclass_refs_dont_replace_standard_refs

 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:alkorzt,项目名称:pypy,代码行数:16,代码来源:test_weakref.py


示例5: _disconnect

 def _disconnect(self, cat, slots, **options): #{{{
     numdel = int(options.get('count', 1))
     if numdel < 0:
         numdel = 0
     if isinstance(slots, dict):
         slots = slots.iteritems()
     sigcat = self._categories
     order, sigslot = sigcat[cat]
     if not slots:
         for name, (funchandler, funclist) in sigslot.iteritems():
             del funclist[:]
     else:
         for name, funclist in slots:
             slist = sigslot[name][1]
             slist_rem = slist.remove
             if not funclist:
                 del slist[:]
                 continue
             for f in funclist:
                 count = 0
                 proxies = [pf for pf in getweakrefs(f) if isinstance(pf, CallableProxyType)]
                 for flist in (proxies, repeat(f)):
                     for p in flist:
                         if numdel and count >= numdel:
                             break
                         try:
                             slist_rem(p)
                         except ValueError:
                             if p == f:
                                 break
                         else:
                             count = count + 1
     if cat in ('around', 'replace'):
         self.reload()
开发者ID:BackupTheBerlios,项目名称:empath-svn,代码行数:34,代码来源:_core.py


示例6: simple_demo

def simple_demo():
    class obj(object):
        def __init__(self, a):
            self.a = a
        def __repr__(self):
            return "obj:{0}".format(self.a)

    o = obj(3)
    r = weakref.ref(o)
    if r():
        print "weakref's referent is alive"
        print "weakref's reference's references/proxies is ", weakref.getweakrefs(o)
    del o
    if r():
        print "weakref's referent is not alive"
        print "weakref's reference's references/proxies is ", weakref.getweakrefs(o)
开发者ID:seckcoder,项目名称:lang-learn,代码行数:16,代码来源:weakref_user.py


示例7: test_subclass_refs_dont_replace_standard_refs

 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)
     assert set(refs) == set((r1, r2, r3))
     if test_support.check_impl_detail():
         self.assertTrue(r2 is refs[0])
         self.assertIn(r1, refs[1:])
         self.assertIn(r3, refs[1:])
开发者ID:Zekom,项目名称:pypyjs,代码行数:18,代码来源:test_weakref.py


示例8: test_getweakrefs

    def test_getweakrefs(self):
        o = C()
        ref1 = weakref.ref(o, self.callback)
        ref2 = weakref.ref(o, self.callback)
        del ref1
        self.assertEqual(weakref.getweakrefs(o), [ref2], "list of refs does not match")

        o = C()
        ref1 = weakref.ref(o, self.callback)
        ref2 = weakref.ref(o, self.callback)
        del ref2
        self.assertEqual(weakref.getweakrefs(o), [ref1], "list of refs does not match")

        del ref1
        self.assertEqual(weakref.getweakrefs(o), [], "list of refs not cleared")

        # assumes ints do not support weakrefs
        self.assertEqual(weakref.getweakrefs(1), [], "list of refs does not match for int")
开发者ID:svanschalkwyk,项目名称:datafari,代码行数:18,代码来源:test_weakref.py


示例9: test_subclass_refs_dont_replace_standard_refs

 def test_subclass_refs_dont_replace_standard_refs(self):
     if test_support.due_to_ironpython_bug("http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=21116"):
         return
     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:BillyboyD,项目名称:main,代码行数:18,代码来源:test_weakref.py


示例10: __eq__

 def __eq__(self, other):
     # We want slots to compare equal if they reference the same function/method
     if isinstance(other, Slot):
         if self.method and not other.method or not self.method and other.method:
             return False
         elif self.method and other.method:
             return self.obj == other.obj and self.name == other.name
         else:
             return self.call == other.call
     # We also want slots to compare equal _to_ the function or method they reference
     else:
         if self.method:
             if hasattr(other, 'im_self'):
                 return self.obj in weakref.getweakrefs(other.im_self) and self.name == other.__name__ 
             else: # `other` is not a method
                 return False
         else:
             return self.call in weakref.getweakrefs(other)
开发者ID:BackupTheBerlios,项目名称:grafity-svn,代码行数:18,代码来源:signals.py


示例11: test_subclass_refs_dont_conflate_callbacks

 def test_subclass_refs_dont_conflate_callbacks(self):
     class MyRef(weakref.ref):
         pass
     o = Object(42)
     r1 = MyRef(o, id)
     r2 = MyRef(o, str)
     self.assertTrue(r1 is not r2)
     refs = list(weakref.getweakrefs(o))
     self.assertIn(r1, refs)
     self.assertIn(r2, refs)
开发者ID:pekkaklarck,项目名称:jython,代码行数:10,代码来源:test_weakref.py


示例12: test_subclass_refs_dont_conflate_callbacks

 def test_subclass_refs_dont_conflate_callbacks(self):
     class MyRef(weakref.ref):
         pass
     o = Object(42)
     r1 = MyRef(o, id)
     r2 = MyRef(o, str)
     self.assert_(r1 is not r2)
     refs = weakref.getweakrefs(o)
     self.assert_(r1 in refs)
     self.assert_(r2 in refs)
开发者ID:alkorzt,项目名称:pypy,代码行数:10,代码来源:test_weakref.py


示例13: tearDown

 def tearDown(self):
     handler = self.loghandler
     # All this is necessary to properly shut down the logging system and
     # avoid a regrtest complaint.  Thanks to Vinay Sajip for the help.
     handler.close()
     logger.removeHandler(handler)
     for ref in weakref.getweakrefs(handler):
         logging._removeHandlerRef(ref)
     del self.loghandler
     logger.setLevel(self._old_level)
     super(LoggingCatcher, self).tearDown()
开发者ID:Electrosoup,项目名称:cornice,代码行数:11,代码来源:support.py


示例14: test_getweakrefs

    def test_getweakrefs(self):
        def runTest():
            o = C()
            ref1 = weakref.ref(o, self.callback)
            ref2 = weakref.ref(o, self.callback)
            del ref1
            return o, ref2

        o, ref2 = runTest()
        test_support.force_gc_collect()
        self.assertTrue(weakref.getweakrefs(o) == [ref2],
                     "list of refs does not match")

        def runTest():
            def runInnerTest():
                o = C()
                ref1 = weakref.ref(o, self.callback)
                ref2 = weakref.ref(o, self.callback)
                del ref2
                return o, ref1

            o, ref1 = runInnerTest()
            test_support.force_gc_collect()
            self.assertTrue(weakref.getweakrefs(o) == [ref1],
                         "list of refs does not match")

            del ref1
            return o

        o = runTest()
        test_support.force_gc_collect()
        self.assertTrue(weakref.getweakrefs(o) == [],
                     "list of refs not cleared")

        # assumes ints do not support weakrefs
        self.assertTrue(weakref.getweakrefs(1) == [],
                     "list of refs does not match for int")
开发者ID:BillyboyD,项目名称:main,代码行数:37,代码来源:test_weakref.py


示例15: test_getweakrefs

    def test_getweakrefs(self):
        o = C()
        ref1 = weakref.ref(o, self.callback)
        ref2 = weakref.ref(o, self.callback)
        del ref1
        extra_collect()
        self.assert_(weakref.getweakrefs(o) == [ref2],
                     "list of refs does not match")

        o = C()
        ref1 = weakref.ref(o, self.callback)
        ref2 = weakref.ref(o, self.callback)
        del ref2
        extra_collect()
        if test_support.is_jython:
            # XXX: Likely a Jython bug: the following inline declared
            # [ref1] list isn't garbage collected no matter how many
            # times we force gc.collect(), which prevents ref1 from
            # being garbage collected after it's del'd below. So we
            # explicitly delete our list
            ref1_list = [ref1]
            self.assert_(weakref.getweakrefs(o) == ref1_list,
            #self.assert_(weakref.getweakrefs(o) == [ref1],
                         "list of refs does not match")
            del ref1_list
        else:
            self.assert_(weakref.getweakrefs(o) == [ref1],
                         "list of refs does not match")

        del ref1
        extra_collect()
        self.assert_(weakref.getweakrefs(o) == [],
                     "list of refs not cleared")

        # assumes ints do not support weakrefs
        self.assert_(weakref.getweakrefs(1) == [],
                     "list of refs does not match for int")
开发者ID:babble,项目名称:babble,代码行数:37,代码来源:test_weakref.py


示例16: runTest

        def runTest():
            def runInnerTest():
                o = C()
                ref1 = weakref.ref(o, self.callback)
                ref2 = weakref.ref(o, self.callback)
                del ref2
                return o, ref1

            o, ref1 = runInnerTest()
            test_support.force_gc_collect()
            self.assertTrue(weakref.getweakrefs(o) == [ref1],
                         "list of refs does not match")

            del ref1
            return o
开发者ID:BillyboyD,项目名称:main,代码行数:15,代码来源:test_weakref.py


示例17: IsSame

def IsSame(o1, o2):
    '''
        This checks for the identity even if one of the parameters is a weak reference

        :param  o1:
            first object to compare

        :param  o2:
            second object to compare

        @raise
            RuntimeError if both of the passed parameters are weak references
    '''
    # get rid of weak refs (we only need special treatment for proxys)
    if IsWeakRef(o1):
        o1 = o1()
    if IsWeakRef(o2):
        o2 = o2()

    # simple case (no weak objects)
    if not IsWeakObj(o1) and not IsWeakObj(o2):
        return o1 is o2

    # all weak proxys
    if IsWeakProxy(o1) and IsWeakProxy(o2):
        if not o1 == o2:
            # if they are not equal, we know they're not the same
            return False

        # but we cannot say anything if they are the same if they are equal
        raise ReferenceError('Cannot check if object is same if both arguments passed are weak objects')

    # one is weak and the other is not
    if IsWeakObj(o1):
        weak = o1
        original = o2
    else:
        weak = o2
        original = o1

    weaks = weakref.getweakrefs(original)
    for w in weaks:
        if w is weak:  # check the weak object identity
            return True

    return False
开发者ID:fabioz,项目名称:ben10,代码行数:46,代码来源:weak_ref.py


示例18: __dealloc

 def __dealloc(self, o):
     for r in weakref.getweakrefs(o):
         self._item_refs.pop(r, None)
开发者ID:dhou,项目名称:gogreen,代码行数:3,代码来源:coroqueue.py


示例19: _swap_refs

def _swap_refs(old, new, ignores):
    """Swap references from one object to another"""
    __internal_swaprefs_ignore__ = "swap_refs"    
    # Swap weak references
    refs = weakref.getweakrefs(old)
    if refs:
        try:
            newRef = weakref.ref(new)
        except ValueError:
            pass
        else:
            for oldRef in refs:
                _swap_refs(oldRef, newRef, ignores + (id(refs),))
    del refs

    deque, defaultdict = _bonus_containers()

    # Swap through garbage collector
    referrers = gc.get_referrers(old)
    for container in referrers:
        if id(container) in ignores:
            continue
        containerType = type(container)
        
        if containerType is list or containerType is deque:
            for index in _find_sequence_indices(container, old):
                container[index] = new
        
        elif containerType is tuple:
            # protect from recursive tuples
            orig = container
            if id(orig) in _recursive_tuple_swap:
                continue
            _recursive_tuple_swap.add(id(orig))
            try:
                container = list(container)
                for index in _find_sequence_indices(container, old):
                    container[index] = new
                container = tuple(container)
                _swap_refs(orig, container, ignores + (id(referrers),))
            finally:
                _recursive_tuple_swap.remove(id(orig))
        
        elif containerType is dict or containerType is defaultdict:
            if "__internal_swaprefs_ignore__" not in container:
                try:
                    if old in container:
                        container[new] = container.pop(old)
                except TypeError:  # Unhashable old value
                    pass
                for k,v in container.iteritems():
                    if v is old:
                        container[k] = new

        elif containerType is set:
            container.remove(old)
            container.add(new)

        elif containerType is type:
            if old in container.__bases__:
                bases = list(container.__bases__)
                bases[bases.index(old)] = new
                container.__bases__ = tuple(bases)
        
        elif type(container) is old:
            container.__class__ = new
        
        elif containerType is _InstanceType:
            if container.__class__ is old:
                container.__class__ = new
开发者ID:abbacode,项目名称:avaloria,代码行数:70,代码来源:reimport.py


示例20: __weakref__

    def __weakref__(self):
        print "Inside weakref"

a = Example()
b = weakref.proxy(a)
# b = a
#b = weakref.ref(a)
print a,b

'''
c = Example()
Example.get_count()
'''
#print "EE =>", sys.getrefcount(Example())
#print "EAA=>", sys.getrefcount(Example)
b._dp("LL")
#b._dp("LL")
print a.__hash__
#del a
gc.collect()
print b.__hash__
print weakref.getweakrefcount(a)
print weakref.getweakrefs(a)
print "ID :a() =>", id(a)
print "ID :b() =>", id(b)
print "HASH :a() =>", hash(a)


#Proxy objects are not hashable regardless of the referent; this avoids a number of problems related to their fundamentally mutable nature, and prevent their use as dictionary keys.
print "HASH :b() =>", hash(b)
开发者ID:haroon-rasheed,项目名称:code_practice,代码行数:30,代码来源:weak_ref.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python weakref.proxy函数代码示例发布时间:2022-05-26
下一篇:
Python weakref.getweakrefcount函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap