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

Python rgc.collect函数代码示例

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

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



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

示例1: test_prebuilt_weakref

 def test_prebuilt_weakref(self):
     import weakref
     from pypy.rlib import rgc
     class A:
         pass
     a = A()
     a.hello = 42
     r1 = weakref.ref(a)
     r2 = weakref.ref(A())
     rgc.collect()
     assert r2() is None
     def fn(n):
         if n:
             r = r1
         else:
             r = r2
         a = r()
         rgc.collect()
         if a is None:
             return -5
         else:
             return a.hello
     c_fn = self.getcompiled(fn, [int])
     res = c_fn(1)
     assert res == 42
     res = c_fn(0)
     assert res == -5
开发者ID:antoine1fr,项目名称:pygirl,代码行数:27,代码来源:test_boehm.py


示例2: f

 def f():
     # numbers optimized for a 8MB space
     for n in [100000, 225000, 250000, 300000, 380000,
               460000, 570000, 800000]:
         os.write(2, 'case %d\n' % n)
         rgc.collect()
         h(n)
     return -42
开发者ID:pombredanne,项目名称:pypy,代码行数:8,代码来源:test_newgc.py


示例3: f

 def f():
     s = lltype.malloc(S)
     s.x = 42
     llop.bare_setfield(lltype.Void, s0, void('next'), s)
     llop.gc_assume_young_pointers(lltype.Void,
                                   llmemory.cast_ptr_to_adr(s0))
     rgc.collect(0)
     return s0.next.x
开发者ID:alkorzt,项目名称:pypy,代码行数:8,代码来源:test_transformed_gc.py


示例4: fn

 def fn(n):
     if n > 0:
         x = BoxedObject(n)
     else:
         x = UnboxedObject(n)
     f.l.append(x)
     rgc.collect()
     return f.l[-1].meth(100)
开发者ID:alkorzt,项目名称:pypy,代码行数:8,代码来源:test_transformed_gc.py


示例5: func

 def func():
     #try:
     a = rgc.malloc_nonmovable(TP, 3, zero=True)
     rgc.collect()
     if a:
         assert not rgc.can_move(a)
         return 0
     return 1
开发者ID:alkorzt,项目名称:pypy,代码行数:8,代码来源:test_transformed_gc.py


示例6: g

 def g():
     n = state.counter
     if n > 0:
         for i in range(5):
             state.a = A(n)
         state.a = None
     rgc.collect()
     return n
开发者ID:antoine1fr,项目名称:pygirl,代码行数:8,代码来源:test_boehm.py


示例7: func

 def func():
     #try:
     from pypy.rlib import rgc
     a = rgc.malloc_nonmovable(TP, 3)
     rgc.collect()
     if a:
         assert not rgc.can_move(a)
         return 0
     return 1
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:9,代码来源:test_transformed_gc.py


示例8: f

 def f():
     del state.freed[:]
     d = add_me()
     rgc.collect()
     # we want the dictionary to be really empty here.  It's hard to
     # ensure in the current implementation after just one collect(),
     # but at least two collects should be enough.
     rgc.collect()
     return len(state.freed)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:9,代码来源:test_rweakkeydict.py


示例9: fn

 def fn():
     result = 0
     for i in range(2):
         a = refs[i]()
         rgc.collect()
         if a is None:
             result += (i+1)
         else:
             result += a.hello * (i+1)
     return result
开发者ID:pombredanne,项目名称:pypy,代码行数:10,代码来源:test_newgc.py


示例10: main

 def main(n):
     states = f(n)
     rgc.collect()
     rgc.collect()
     err = 1001
     for state in states:
         if state.num != 1001:
             err = state.num
             print 'ERROR:', err
     return err
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:10,代码来源:test_del.py


示例11: fn

 def fn(n):
     if n:
         r = r1
     else:
         r = r2
     a = r()
     rgc.collect()
     if a is None:
         return -5
     else:
         return a.hello
开发者ID:antoine1fr,项目名称:pygirl,代码行数:11,代码来源:test_boehm.py


示例12: collect

def collect(space):
    "Run a full collection."
    # First clear the method cache.  See test_gc for an example of why.
    if space.config.objspace.std.withmethodcache:
        from pypy.objspace.std.typeobject import MethodCache
        cache = space.fromcache(MethodCache)
        cache.clear()
        if space.config.objspace.std.withmapdict:
            from pypy.objspace.std.mapdict import IndexCache
            cache = space.fromcache(IndexCache)
            cache.clear()
    rgc.collect()
    return space.wrap(0)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:13,代码来源:interp_gc.py


示例13: fn

 def fn(n):
     id_prebuilt1 = compute_unique_id(u.x)
     if n > 0:
         x = BoxedObject(n)
     else:
         x = UnboxedObject(n)
     id_x1 = compute_unique_id(x)
     rgc.collect() # check that a prebuilt tagged pointer doesn't explode
     id_prebuilt2 = compute_unique_id(u.x)
     id_x2 = compute_unique_id(x)
     print u.x, id_prebuilt1, id_prebuilt2
     print x, id_x1, id_x2
     return ((id_x1 == id_x2) * 1 +
             (id_prebuilt1 == id_prebuilt2) * 10 +
             (id_x1 != id_prebuilt1) * 100)
开发者ID:enyst,项目名称:plexnet,代码行数:15,代码来源:test_gc.py


示例14: h

 def h(n):
     x3 = g(3)
     x4 = g(3)
     x1 = g(n)
     build(x1, n)       # can collect!
     check(x1, n, 1)
     build(x3, 3)
     x2 = g(n//2)       # allocate more and try again
     build(x2, n//2)
     check(x1, n, 11)
     check(x2, n//2, 12)
     build(x4, 3)
     check(x3, 3, 13)   # check these old objects too
     check(x4, 3, 14)   # check these old objects too
     rgc.collect()
     check(x1, n, 21)
     check(x2, n//2, 22)
     check(x3, 3, 23)
     check(x4, 3, 24)
开发者ID:pombredanne,项目名称:pypy,代码行数:19,代码来源:test_newgc.py


示例15: define_prebuilt_weakref

 def define_prebuilt_weakref(cls):
     import weakref
     class A:
         pass
     a = A()
     a.hello = 42
     refs = [weakref.ref(a), weakref.ref(A())]
     rgc.collect()
     def fn():
         result = 0
         for i in range(2):
             a = refs[i]()
             rgc.collect()
             if a is None:
                 result += (i+1)
             else:
                 result += a.hello * (i+1)
         return result
     return fn
开发者ID:pombredanne,项目名称:pypy,代码行数:19,代码来源:test_newgc.py


示例16: f

 def f():
     d = RWeakValueDictionary(X)
     x1, x3 = g(d)
     rgc.collect(); rgc.collect()
     assert d.get("abc") is x1
     assert d.get("def") is None
     assert d.get("ghi") is x3
     assert d.get("hello") is None
     d.set("abc", None)
     assert d.get("abc") is None
     assert d.get("def") is None
     assert d.get("ghi") is x3
     assert d.get("hello") is None
     # resizing should also work
     for i in range(loop):
         d.set(str(i), x1)
     for i in range(loop):
         assert d.get(str(i)) is x1
     assert d.get("abc") is None
     assert d.get("def") is None
     assert d.get("ghi") is x3
     assert d.get("hello") is None
     # a subclass
     y = Y()
     d.set("hello", y)
     assert d.get("hello") is y
     # storing a lot of Nones
     for i in range(loop, loop*2-5):
         d.set('%dfoobar' % i, x1)
     for i in range(loop):
         d.set(str(i), None)
     for i in range(loop):
         assert d.get(str(i)) is None
     assert d.get("abc") is None
     assert d.get("def") is None
     assert d.get("ghi") is x3
     assert d.get("hello") is y
     for i in range(loop, loop*2-5):
         assert d.get('%dfoobar' % i) is x1
开发者ID:alkorzt,项目名称:pypy,代码行数:39,代码来源:test_rweakref.py


示例17: f

 def f():
     d = prebuilt
     if d is None:
         d = RWeakKeyDictionary(KX, VX)
     k1, k3, v1, v2, v3 = g(d)
     rgc.collect(); rgc.collect()
     assert d.get(k1) is v1
     assert d.get(k3) is v3
     assert d.get(k1) is not v2
     assert d.get(k3) is not v2
     assert d.length() == 2
     d.set(k1, None)
     assert d.get(k1) is None
     assert d.get(k3) is v3
     assert d.length() == 1
     # resizing should also work
     lots_of_keys = [KX() for i in range(loop)]
     for k in lots_of_keys:
         d.set(k, v1)
     for k in lots_of_keys:
         assert d.get(k) is v1
     assert d.get(k1) is None
     assert d.get(k3) is v3
     assert d.length() == loop + 1
     # a subclass
     ky = KY()
     vy = VY()
     d.set(ky, vy)
     assert d.get(ky) is vy
     assert d.length() == loop + 2
     # deleting by storing Nones
     for k in lots_of_keys:
         d.set(k, None)
     for k in lots_of_keys:
         assert d.get(k) is None
     assert d.get(k1) is None
     assert d.get(k3) is v3
     assert d.get(ky) is vy
     assert d.length() == 2
开发者ID:Sherlockhlt,项目名称:pypy,代码行数:39,代码来源:test_rweakkeydict.py


示例18: test_multiple_prebuilt_dead_weakrefs

    def test_multiple_prebuilt_dead_weakrefs(self):
        class A:
            pass
        a1 = A()
        w1 = weakref.ref(a1)
        a2 = A()
        w2 = weakref.ref(a2)
        a3 = A()
        w3 = weakref.ref(a3)
        a4 = A()
        w4 = weakref.ref(a4)

        del a1, a3
        rgc.collect()
        assert w1() is None
        assert w3() is None

        def f(n):
            if n > 0:
                if n > 5:
                    r = w1
                else:
                    r = w3
                assert r() is None
            else:
                if n < -5:
                    r = w2
                else:
                    r = w4
                assert r() is not None
            return r() is not None
        res = self.interpret(f, [1])
        assert res == False
        res = self.interpret(f, [0])
        assert res == True
        res = self.interpret(f, [100])
        assert res == False
        res = self.interpret(f, [-100])
        assert res == True
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:39,代码来源:test_rweakref.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python rmmap.mmap函数代码示例发布时间:2022-05-27
下一篇:
Python rgc.can_move函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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