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


Python weakref.getweakrefs函数代码示例

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


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


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