本文整理匯總了Python中gc.get_threshold方法的典型用法代碼示例。如果您正苦於以下問題:Python gc.get_threshold方法的具體用法?Python gc.get_threshold怎麽用?Python gc.get_threshold使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類gc
的用法示例。
在下文中一共展示了gc.get_threshold方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_threshold
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import get_threshold [as 別名]
def test_threshold(self):
"""test 'gci threshold'."""
g1, g2, g3 = gc.get_threshold()
output = self.run_command("gci threshold", exitcode=0)
self.assertIn("G1: " + str(g1), output)
self.assertIn("G2: " + str(g2), output)
self.assertIn("G3: " + str(g3), output)
n1 = g1 + 1
n2 = g2 + 1
n3 = g3 + 1
output = self.run_command("gci threshold {} {} {}".format(n1, n2, n3), exitcode=0)
self.assertEqual(output.replace("\n", ""), "")
output = self.run_command("gci threshold", exitcode=0)
self.assertIn("G1: " + str(n1), output)
self.assertIn("G2: " + str(n2), output)
self.assertIn("G3: " + str(n3), output)
gc.set_threshold(g1, g2, g3)
output = self.run_command("gci threshold", exitcode=0)
self.assertIn("G1: " + str(g1), output)
self.assertIn("G2: " + str(g2), output)
self.assertIn("G3: " + str(g3), output)
示例2: test_len_race
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import get_threshold [as 別名]
def test_len_race(self):
# Extended sanity checks for len() in the face of cyclic collection
self.addCleanup(gc.set_threshold, *gc.get_threshold())
for th in range(1, 100):
N = 20
gc.collect(0)
gc.set_threshold(th, th, th)
items = [RefCycle() for i in range(N)]
s = WeakSet(items)
del items
# All items will be collected at next garbage collection pass
it = iter(s)
try:
next(it)
except StopIteration:
pass
n1 = len(s)
del it
n2 = len(s)
self.assertGreaterEqual(n1, 0)
self.assertLessEqual(n1, N)
self.assertGreaterEqual(n2, 0)
self.assertLessEqual(n2, n1)
示例3: test_del_newclass
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import get_threshold [as 別名]
def test_del_newclass(self):
# __del__ methods can trigger collection, make this to happen
thresholds = gc.get_threshold()
gc.enable()
gc.set_threshold(1)
class A(object):
def __del__(self):
dir(self)
a = A()
del a
gc.disable()
gc.set_threshold(*thresholds)
# The following two tests are fragile:
# They precisely count the number of allocations,
# which is highly implementation-dependent.
# For example:
# - disposed tuples are not freed, but reused
# - the call to assertEqual somehow avoids building its args tuple
示例4: check_gc_during_creation
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import get_threshold [as 別名]
def check_gc_during_creation(self, makeref):
thresholds = gc.get_threshold()
gc.set_threshold(1, 1, 1)
gc.collect()
class A:
pass
def callback(*args):
pass
referenced = A()
a = A()
a.a = a
a.wr = makeref(referenced)
try:
# now make sure the object and the ref get labeled as
# cyclic trash:
a = A()
weakref.ref(referenced, callback)
finally:
gc.set_threshold(*thresholds)
示例5: check_len_race
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import get_threshold [as 別名]
def check_len_race(self, dict_type, cons):
# Extended sanity checks for len() in the face of cyclic collection
self.addCleanup(gc.set_threshold, *gc.get_threshold())
for th in range(1, 100):
N = 20
gc.collect(0)
gc.set_threshold(th, th, th)
items = [RefCycle() for i in range(N)]
dct = dict_type(cons(o) for o in items)
del items
# All items will be collected at next garbage collection pass
it = dct.iteritems()
try:
next(it)
except StopIteration:
pass
n1 = len(dct)
del it
n2 = len(dct)
self.assertGreaterEqual(n1, 0)
self.assertLessEqual(n1, N)
self.assertGreaterEqual(n2, 0)
self.assertLessEqual(n2, n1)
示例6: test_del_newclass
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import get_threshold [as 別名]
def test_del_newclass(self):
# __del__ methods can trigger collection, make this to happen
thresholds = gc.get_threshold()
gc.enable()
gc.set_threshold(1)
class A(object):
def __del__(self):
dir(self)
a = A()
del a
gc.disable()
gc.set_threshold(*thresholds)
# The following two tests are fragile:
# They precisely count the number of allocations,
# which is highly implementation-dependent.
# For example, disposed tuples are not freed, but reused.
# To minimize variations, though, we first store the get_count() results
# and check them at the end.
示例7: check_len_race
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import get_threshold [as 別名]
def check_len_race(self, dict_type, cons):
# Extended sanity checks for len() in the face of cyclic collection
self.addCleanup(gc.set_threshold, *gc.get_threshold())
for th in range(1, 100):
N = 20
gc.collect(0)
gc.set_threshold(th, th, th)
items = [RefCycle() for i in range(N)]
dct = dict_type(cons(o) for o in items)
del items
# All items will be collected at next garbage collection pass
it = dct.items()
try:
next(it)
except StopIteration:
pass
n1 = len(dct)
del it
n2 = len(dct)
self.assertGreaterEqual(n1, 0)
self.assertLessEqual(n1, N)
self.assertGreaterEqual(n2, 0)
self.assertLessEqual(n2, n1)