本文整理汇总了Python中sys.grc函数的典型用法代码示例。如果您正苦于以下问题:Python grc函数的具体用法?Python grc怎么用?Python grc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了grc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ints
def test_ints(self):
i = 42000123
refcnt = grc(i)
ci = c_int(i)
self.assertEqual(refcnt, grc(i))
self.assertEqual(ci._objects, None)
return
示例2: test_X
def test_X(self):
class X(Structure):
_fields_ = [("p", POINTER(c_char_p))]
x = X()
i = c_char_p("abc def")
from sys import getrefcount as grc
shout "2?", grc(i)
x.p = pointer(i)
shout "3?", grc(i)
for i in range(320):
c_int(99)
x.p[0]
shout x.p[0]
## del x
## shout "2?", grc(i)
## del i
import gc
gc.collect()
for i in range(320):
c_int(99)
x.p[0]
shout x.p[0]
shout x.p.contents
## shout x._objects
x.p[0] = "spam spam"
## shout x.p[0]
shout "+" * 42
shout x._objects
示例3: test_1
def test_1(self):
try:
from sys import getrefcount as grc
except ImportError:
return unittest.skip("no sys.getrefcount()")
f = dll._testfunc_callback_i_if
f.restype = ctypes.c_int
f.argtypes = [ctypes.c_int, MyCallback]
def callback(value):
#print "called back with", value
return value
self.assertEqual(grc(callback), 2)
cb = MyCallback(callback)
self.assertGreater(grc(callback), 2)
result = f(-10, cb)
self.assertEqual(result, -18)
cb = None
gc.collect()
self.assertEqual(grc(callback), 2)
示例4: test_1
def test_1(self):
from sys import getrefcount as grc
f = dll._testfunc_callback_i_if
f.restype = ctypes.c_int
f.argtypes = [ctypes.c_int, MyCallback]
def callback(value):
#print "called back with", value
return value
if not test_support.due_to_ironpython_bug("http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=22374"):
self.assertEqual(grc(callback), 2)
cb = MyCallback(callback)
if not test_support.due_to_ironpython_bug("http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=22374"):
self.assertTrue(grc(callback) > 2)
result = f(-10, cb)
self.assertEqual(result, -18)
cb = None
gc.collect()
if not test_support.due_to_ironpython_bug("http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=22374"):
self.assertEqual(grc(callback), 2)
示例5: X_test
def X_test(self):
class X(Structure):
_fields_ = [("p", POINTER(c_char_p))]
x = X()
i = c_char_p("abc def")
from sys import getrefcount as grc
print("2?", grc(i))
x.p = pointer(i)
print("3?", grc(i))
for i in range(320):
c_int(99)
x.p[0]
print(x.p[0])
## del x
## print "2?", grc(i)
## del i
import gc
gc.collect()
for i in range(320):
c_int(99)
x.p[0]
print(x.p[0])
print(x.p.contents)
## print x._objects
x.p[0] = "spam spam"
## print x.p[0]
print("+" * 42)
print(x._objects)
示例6: test_via
def test_via(self, vlist=['v',]): # vlist is just to make v unoptimizable
# Special tests for the via classifier
from sys import getrefcount as grc
import gc
iso = self.iso
hp = self.Use
d = {}
k = ('k',)
v = tuple(vlist) # Make sure v is not optimized to a constant
d[k] = v
d[v] = v
rck = grc(k)
rcv = grc(v)
s = iso(v)
self.assert_( s.byvia.kind == hp.Via("_.f_locals['v']", "_[('k',)]", "_[('v',)]", '_.keys()[1]') or
s.byvia.kind == hp.Via("_.f_locals['v']", "_[('k',)]", "_[('v',)]", '_.keys()[0]'))
del s
gc.collect()
gc.collect()
self.aseq(grc(k), rck)
self.aseq(grc(v), rcv )
示例7: X_test
def X_test(self):
class X(Structure):
_fields_ = [('p', POINTER(c_char_p))]
x = X()
i = c_char_p('abc def')
from sys import getrefcount as grc
print '2?', grc(i)
x.p = pointer(i)
print '3?', grc(i)
for i in range(320):
c_int(99)
x.p[0]
print x.p[0]
import gc
gc.collect()
for i in range(320):
c_int(99)
x.p[0]
print x.p[0]
print x.p.contents
x.p[0] = 'spam spam'
print '+' * 42
print x._objects
示例8: test_c_char_p
def test_c_char_p(self):
if test_support.due_to_ironpython_bug("http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=22374"):
return
s = "Hello, World"
refcnt = grc(s)
cs = c_char_p(s)
self.assertEqual(refcnt + 1, grc(s))
self.assertSame(cs._objects, s)
示例9: test_ints
def test_ints(self):
if test_support.due_to_ironpython_bug("http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=22374"):
return
i = 42000123
refcnt = grc(i)
ci = c_int(i)
self.assertEqual(refcnt, grc(i))
self.assertEqual(ci._objects, None)
示例10: test_PyObj_FromPtr
def test_PyObj_FromPtr(self):
s = 'abc def ghi jkl'
ref = grc(s)
pyobj = PyObj_FromPtr(id(s))
self.assertIs(s, pyobj)
self.assertEqual(grc(s), ref + 1)
del pyobj
self.assertEqual(grc(s), ref)
示例11: test_c_char_p
def test_c_char_p(self):
if grc is None:
return unittest.skip("no sys.getrefcount()")
s = b"Hello, World"
refcnt = grc(s)
cs = c_char_p(s)
self.assertEqual(refcnt + 1, grc(s))
self.assertSame(cs._objects, s)
示例12: test_ints
def test_ints(self):
if grc is None:
return unittest.skip("no sys.getrefcount()")
i = 42000123
refcnt = grc(i)
ci = c_int(i)
self.assertEqual(refcnt, grc(i))
self.assertEqual(ci._objects, None)
示例13: test_PyObj_FromPtr
def test_PyObj_FromPtr(self):
s = "abc def ghi jkl"
ref = grc(s)
# id(python-object) is the address
pyobj = PyObj_FromPtr(id(s))
self.assertTrue(s is pyobj)
self.assertEqual(grc(s), ref + 1)
del pyobj
self.assertEqual(grc(s), ref)
示例14: test_above_30
def test_above_30(self):
"""Message above 30 bytes are never copied by 0MQ."""
for i in range(5, 16): # 32, 64,..., 65536
s = (2**i)*x
self.assertEquals(grc(s), 2)
m = zmq.Frame(s)
self.assertEquals(grc(s), 4)
del m
self.assertEquals(grc(s), 2)
del s
示例15: test_pyobject
def test_pyobject(self):
o = ()
from sys import getrefcount as grc
for o in ((), [], object()):
initial = grc(o)
self.check_type(py_object, o)
before = grc(o)
self.check_type(py_object, o)
after = grc(o)
self.assertEqual((after, o), (before, o))