本文整理汇总了Python中pypy.rlib.rgc.collect函数的典型用法代码示例。如果您正苦于以下问题:Python collect函数的具体用法?Python collect怎么用?Python collect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了collect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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
示例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
示例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)
示例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
示例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
示例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
示例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)
示例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
示例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
示例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
示例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)
示例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)
示例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)
示例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