本文整理匯總了Python中gc.DEBUG_SAVEALL屬性的典型用法代碼示例。如果您正苦於以下問題:Python gc.DEBUG_SAVEALL屬性的具體用法?Python gc.DEBUG_SAVEALL怎麽用?Python gc.DEBUG_SAVEALL使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類gc
的用法示例。
在下文中一共展示了gc.DEBUG_SAVEALL屬性的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_saveall
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import DEBUG_SAVEALL [as 別名]
def test_saveall(self):
# Verify that cyclic garbage like lists show up in gc.garbage if the
# SAVEALL option is enabled.
# First make sure we don't save away other stuff that just happens to
# be waiting for collection.
gc.collect()
# if this fails, someone else created immortal trash
self.assertEqual(gc.garbage, [])
L = []
L.append(L)
id_L = id(L)
debug = gc.get_debug()
gc.set_debug(debug | gc.DEBUG_SAVEALL)
del L
gc.collect()
gc.set_debug(debug)
self.assertEqual(len(gc.garbage), 1)
obj = gc.garbage.pop()
self.assertEqual(id(obj), id_L)
示例2: init
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import DEBUG_SAVEALL [as 別名]
def init(self):
import gc
# gc.DEBUG_OBJECTS not present in python3
gc.set_debug(gc.DEBUG_UNCOLLECTABLE|gc.DEBUG_SAVEALL)
self.prompt = ">"
self.previous = ""
self.set_tooltip(_("Enter Python expressions"))
self.gc = gc
self.env = {"dbstate": self.gui.dbstate,
"uistate": self.gui.uistate,
"db": self.gui.dbstate.db,
"gc": self.gc,
"self": self,
"Date": gramps.gen.lib.Date,
}
# GUI setup:
self.gui.textview.set_editable(True)
self.set_text("Python %s\n%s " % (sys.version, self.prompt))
self.gui.textview.connect('key-press-event', self.on_key_press)
示例3: test_saveall
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import DEBUG_SAVEALL [as 別名]
def test_saveall():
# Verify that cyclic garbage like lists show up in gc.garbage if the
# SAVEALL option is enabled.
# First make sure we don't save away other stuff that just happens to
# be waiting for collection.
gc.collect()
vereq(gc.garbage, []) # if this fails, someone else created immortal trash
L = []
L.append(L)
id_L = id(L)
debug = gc.get_debug()
gc.set_debug(debug | gc.DEBUG_SAVEALL)
del L
gc.collect()
gc.set_debug(debug)
vereq(len(gc.garbage), 1)
obj = gc.garbage.pop()
vereq(id(obj), id_L)
示例4: test_saveall
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import DEBUG_SAVEALL [as 別名]
def test_saveall(self):
# Verify that cyclic garbage like lists show up in gc.garbage if the
# SAVEALL option is enabled.
# First make sure we don't save away other stuff that just happens to
# be waiting for collection.
gc.collect()
# if this fails, someone else created immortal trash
self.assertEqual(gc.garbage, [])
L = []
L.append(L)
id_L = id(L)
debug = gc.get_debug()
gc.set_debug(debug | gc.DEBUG_SAVEALL)
del L
gc.collect()
gc.set_debug(debug)
self.assertEqual(len(gc.garbage), 1)
obj = gc.garbage.pop()
self.assertEqual(id(obj), id_L)
示例5: test_debug_stats
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import DEBUG_SAVEALL [as 別名]
def test_debug_stats(self):
self.assertEqual(1,gc.DEBUG_STATS)
self.assertEqual(2,gc.DEBUG_COLLECTABLE)
self.assertEqual(4,gc.DEBUG_UNCOLLECTABLE)
self.assertEqual(8,gc.DEBUG_INSTANCES)
self.assertEqual(16,gc.DEBUG_OBJECTS)
self.assertEqual(32,gc.DEBUG_SAVEALL)
self.assertEqual(62,gc.DEBUG_LEAK)
示例6: test_get_debug
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import DEBUG_SAVEALL [as 別名]
def test_get_debug(self):
state = [0,gc.DEBUG_STATS,gc.DEBUG_COLLECTABLE,gc.DEBUG_UNCOLLECTABLE,gc.DEBUG_INSTANCES,gc.DEBUG_OBJECTS,gc.DEBUG_SAVEALL,gc.DEBUG_LEAK]
result = gc.get_debug()
if result not in state:
self.fail("Returned value of getdebug method is not valid value:" + str(result))
示例7: test_debug_stats
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import DEBUG_SAVEALL [as 別名]
def test_debug_stats(self):
self.assertEqual(1,gc.DEBUG_STATS)
self.assertEqual(2,gc.DEBUG_COLLECTABLE)
self.assertEqual(4,gc.DEBUG_UNCOLLECTABLE)
self.assertEqual(32,gc.DEBUG_SAVEALL)
self.assertEqual(38,gc.DEBUG_LEAK)
示例8: test_get_debug
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import DEBUG_SAVEALL [as 別名]
def test_get_debug(self):
state = [0,gc.DEBUG_STATS,gc.DEBUG_COLLECTABLE,gc.DEBUG_UNCOLLECTABLE,gc.DEBUG_SAVEALL,gc.DEBUG_LEAK]
result = gc.get_debug()
if result not in state:
self.fail("Returned value of getdebug method is not valid value:" + str(result))
示例9: test_garbage_at_shutdown
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import DEBUG_SAVEALL [as 別名]
def test_garbage_at_shutdown(self):
import subprocess
code = """if 1:
import gc
import _testcapi
@_testcapi.with_tp_del
class X:
def __init__(self, name):
self.name = name
def __repr__(self):
return "<X %%r>" %% self.name
def __tp_del__(self):
pass
x = X('first')
x.x = x
x.y = X('second')
del x
gc.set_debug(%s)
"""
def run_command(code):
p = subprocess.Popen([sys.executable, "-Wd", "-c", code],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
p.stdout.close()
p.stderr.close()
self.assertEqual(p.returncode, 0)
self.assertEqual(stdout.strip(), b"")
return strip_python_stderr(stderr)
stderr = run_command(code % "0")
self.assertIn(b"ResourceWarning: gc: 2 uncollectable objects at "
b"shutdown; use", stderr)
self.assertNotIn(b"<X 'first'>", stderr)
# With DEBUG_UNCOLLECTABLE, the garbage list gets printed
stderr = run_command(code % "gc.DEBUG_UNCOLLECTABLE")
self.assertIn(b"ResourceWarning: gc: 2 uncollectable objects at "
b"shutdown", stderr)
self.assertTrue(
(b"[<X 'first'>, <X 'second'>]" in stderr) or
(b"[<X 'second'>, <X 'first'>]" in stderr), stderr)
# With DEBUG_SAVEALL, no additional message should get printed
# (because gc.garbage also contains normally reclaimable cyclic
# references, and its elements get printed at runtime anyway).
stderr = run_command(code % "gc.DEBUG_SAVEALL")
self.assertNotIn(b"uncollectable objects at shutdown", stderr)