All Samples(2202) | Call(1940) | Derive(0) | Import(262)
getrefcount(object) -> integer Return the reference count of object. The count returned is generally one higher than you might expect, because it includes the (temporary) reference as an argument to getrefcount().
src/p/y/pycsdp-HEAD/examples/example.py pycsdp(Download)
#!/usr/bin/env python
from __future__ import division
import numpy as np
from pycsdp import _csdp
from sys import getrefcount
c1 = np.array([[2.0, 1.0],
[1.0, 2.0]])
src/f/e/fey-HEAD/trunk/src/utils/CopyOnWrite.py fey(Download)
along with this program. If not, see <http://www.gnu.org/licenses/>. """ from sys import getrefcount from gc import get_referrers from fey.utils.Decorator import Decorator
# If there are more than the baseline
# references to its data...
refcount = getrefcount(field)
if refcount > 3:
if debug >= 1:
src/f/e/fey-HEAD/src/utils/CopyOnWrite.py fey(Download)
along with this program. If not, see <http://www.gnu.org/licenses/>. """ from sys import getrefcount from gc import get_referrers from fey.utils.Decorator import Decorator
# If there are more than the baseline
# references to its data...
refcount = getrefcount(field)
if refcount > 3:
if debug >= 1:
src/i/t/itools-HEAD/handlers/database.py itools(Download)
from os import mkdir from os.path import basename, join from subprocess import call, PIPE, CalledProcessError from sys import getrefcount # Import from itools from itools.core import LRUCache, send_subprocess, freeze
# Skip externally referenced handlers (refcount should be 3:
# one for the cache, one for the local variable and one for
# the argument passed to getrefcount).
refcount = getrefcount(handler)
if refcount > 3:
continue
# Skip modified (not new) handlers
src/p/y/Pythagora-HEAD/iconretriever.py Pythagora(Download)
import os import urllib from glob import glob from sys import getrefcount import threading import time
def run(self):
while self.running:
if self.toFetch:
item = self.toFetch.pop(0)
try:
# if we are the only one holding on to the item, get rid of it.
if getrefcount(item) > 2:
src/p/y/Pythagora-HEAD/CurrentPlaylistForm.py Pythagora(Download)
from PyQt4.QtGui import QWidget, QInputDialog, QKeySequence, QListWidget, QIcon, QListWidgetItem from PyQt4 import uic from time import time from sys import getrefcount import auxilia import iconretriever
def loadIcons(self):
while self.retriever.icons:
item, icon = self.retriever.icons.pop(0)
if getrefcount(item) > 2:
item.setIcon(QIcon(icon))
def trackSearch(self, key):
src/f/e/fey-HEAD/trunk/src/utils/testCopyOnWrite.py fey(Download)
"""
from fey.utils import UnitTest
from fey.utils.CopyOnWrite import CopyOnWrite as COW
from sys import getrefcount
class Foo(object):
def __init__(self):
f = Foo()
# Check that the refcount is at the base level
assert getrefcount(f.bar) == 2, getrefcount(f.bar)
assert getrefcount(f._Foo__day) == 2, getrefcount(f._Foo__day)
f.mBar()
assert not f.getCopied()
assert f.bar[4] == 'd'
# Check that the refcount is at the base level
assert getrefcount(f.bar) == 2, getrefcount(f.bar)
assert getrefcount(f._Foo__day) == 2, getrefcount(f._Foo__day)
assert f._Foo__day == set((1,2,3,4))
# Check that the refcount is at the base level
assert getrefcount(f.bar) == 2, getrefcount(f.bar)
assert getrefcount(f._Foo__day) == 2, getrefcount(f._Foo__day)
f.mBoth()
assert not f.getCopied()
assert f.bar[4] == 'd'
assert f.bar[5] == 'e'
assert f._Foo__day == set((1,2,3,4,5))
# Check that the refcount is at the base level
assert getrefcount(f.bar) == 2, getrefcount(f.bar)
# Check that the refcount is at the base level
assert getrefcount(f.bar) == 2, getrefcount(f.bar)
assert getrefcount(f._Foo__day) == 2, getrefcount(f._Foo__day)
m = Man()
# Check that the refcount is at the base level
assert getrefcount(m.bar) == 2, getrefcount(m.bar)
assert getrefcount(m._Foo__day) == 2, getrefcount(m._Foo__day)
assert getrefcount(m._Man__day) == 2, getrefcount(m._Man__day)
assert m.bar[4] == 'd'
# Check that the refcount is at the base level
assert getrefcount(m.bar) == 2, getrefcount(m.bar)
assert getrefcount(m._Foo__day) == 2, getrefcount(m._Foo__day)
assert getrefcount(m._Man__day) == 2, getrefcount(m._Man__day)
m.mDay()
assert not m.getCopied()
assert m._Foo__day == set((1,2,3))
assert m._Man__day == set((11,12,13,14))
# Check that the refcount is at the base level
assert getrefcount(m.bar) == 2, getrefcount(m.bar)
# Check that the refcount is at the base level
assert getrefcount(m.bar) == 2, getrefcount(m.bar)
assert getrefcount(m._Foo__day) == 2, getrefcount(m._Foo__day)
assert getrefcount(m._Man__day) == 2, getrefcount(m._Man__day)
m.mBoth()
assert m.bar[4] == 'd'
assert m.bar[5] == 'e'
assert m._Foo__day == set((1,2,3,5))
assert m._Man__day == set((11,12,13,14))
# Check that the refcount is at the base level
assert getrefcount(m.bar) == 2, getrefcount(m.bar)
# Check that the refcount is at the base level
assert getrefcount(m.bar) == 2, getrefcount(m.bar)
assert getrefcount(m._Foo__day) == 2, getrefcount(m._Foo__day)
assert getrefcount(m._Man__day) == 2, getrefcount(m._Man__day)
pass
b = Man()
# Check that the refcount is at the base level
assert getrefcount(b.bar) == 2, getrefcount(b.bar)
assert getrefcount(b._Foo__day) == 2, getrefcount(b._Foo__day)
assert getrefcount(b._Man__day) == 2, getrefcount(b._Man__day)
c = b.copy()
# Check that the refcounts have been incremented on b
assert getrefcount(b.bar) == 3, getrefcount(b.bar)
assert getrefcount(b._Foo__day) == 3, getrefcount(b._Foo__day)
assert getrefcount(b._Man__day) == 3, getrefcount(b._Man__day)
assert getrefcount(b._Man__day) == 3, getrefcount(b._Man__day)
# Check that the refcounts have been incremented on c
assert getrefcount(c.bar) == 3, getrefcount(c.bar)
assert getrefcount(c._Foo__day) == 3, getrefcount(c._Foo__day)
assert getrefcount(c._Man__day) == 3, getrefcount(c._Man__day)
assert 4 not in c.bar
# Check that the refcounts have been adjusted
assert getrefcount(b.bar) == 2, getrefcount(b.bar)
assert getrefcount(b._Foo__day) == 3, getrefcount(b._Foo__day)
assert getrefcount(b._Man__day) == 3, getrefcount(b._Man__day)
# Check that the refcounts have been adjusted
assert getrefcount(c.bar) == 2, getrefcount(c.bar)
assert getrefcount(c._Foo__day) == 3, getrefcount(c._Foo__day)
assert getrefcount(c._Man__day) == 3, getrefcount(c._Man__day)
assert c._Man__day == set((11,12,13))
# Check that the refcounts have been adjusted
assert getrefcount(b.bar) == 2, getrefcount(b.bar)
assert getrefcount(b._Foo__day) == 3, getrefcount(b._Foo__day)
assert getrefcount(b._Man__day) == 2, getrefcount(b._Man__day)
# Check that the refcounts have been adjusted
assert getrefcount(c.bar) == 2, getrefcount(c.bar)
assert getrefcount(c._Foo__day) == 3, getrefcount(c._Foo__day)
assert getrefcount(c._Man__day) == 2, getrefcount(c._Man__day)
assert c._Man__day == set((11,12,13))
# Check that the refcounts have been adjusted
assert getrefcount(b.bar) == 2, getrefcount(b.bar)
assert getrefcount(b._Foo__day) == 2, getrefcount(b._Foo__day)
assert getrefcount(b._Man__day) == 2, getrefcount(b._Man__day)
# Check that the refcounts have been adjusted
assert getrefcount(c.bar) == 2, getrefcount(c.bar)
assert getrefcount(c._Foo__day) == 2, getrefcount(c._Foo__day)
assert getrefcount(c._Man__day) == 2, getrefcount(c._Man__day)
assert c._Man__day == set((11,12,13))
# Check that the refcounts have not been adjusted
assert getrefcount(b.bar) == 2, getrefcount(b.bar)
assert getrefcount(b._Foo__day) == 2, getrefcount(b._Foo__day)
assert getrefcount(b._Man__day) == 2, getrefcount(b._Man__day)
# Check that the refcounts have not been adjusted
assert getrefcount(c.bar) == 2, getrefcount(c.bar)
assert getrefcount(c._Foo__day) == 2, getrefcount(c._Foo__day)
assert getrefcount(c._Man__day) == 2, getrefcount(c._Man__day)
assert 4 not in c.bar
# Check that the refcounts have not been adjusted
assert getrefcount(b.bar) == 2, getrefcount(b.bar)
assert getrefcount(b._Foo__day) == 3, getrefcount(b._Foo__day)
assert getrefcount(b._Man__day) == 3, getrefcount(b._Man__day)
# Check that the refcounts have not been adjusted
assert getrefcount(c.bar) == 2, getrefcount(c.bar)
assert getrefcount(c._Foo__day) == 3, getrefcount(c._Foo__day)
assert getrefcount(c._Man__day) == 3, getrefcount(c._Man__day)
assert c._Man__day == set((11,12,13))
# Check that the refcounts have not been adjusted
assert getrefcount(b.bar) == 2, getrefcount(b.bar)
assert getrefcount(b._Foo__day) == 3, getrefcount(b._Foo__day)
assert getrefcount(b._Man__day) == 2, getrefcount(b._Man__day)
# Check that the refcounts have not been adjusted
assert getrefcount(c.bar) == 2, getrefcount(c.bar)
assert getrefcount(c._Foo__day) == 3, getrefcount(c._Foo__day)
assert getrefcount(c._Man__day) == 2, getrefcount(c._Man__day)
assert c._Man__day == set((11,12,13))
# Check that the refcounts have not been adjusted
assert getrefcount(b.bar) == 2, getrefcount(b.bar)
assert getrefcount(b._Foo__day) == 2, getrefcount(b._Foo__day)
assert getrefcount(b._Man__day) == 2, getrefcount(b._Man__day)
# Check that the refcounts have not been adjusted
assert getrefcount(c.bar) == 2, getrefcount(c.bar)
assert getrefcount(c._Foo__day) == 2, getrefcount(c._Foo__day)
assert getrefcount(c._Man__day) == 2, getrefcount(c._Man__day)
assert c._Man__day == set((11,12,13))
# Check that the refcounts have not been adjusted
assert getrefcount(b.bar) == 2, getrefcount(b.bar)
assert getrefcount(b._Foo__day) == 2, getrefcount(b._Foo__day)
assert getrefcount(b._Man__day) == 2, getrefcount(b._Man__day)
# Check that the refcounts have not been adjusted
assert getrefcount(c.bar) == 2, getrefcount(c.bar)
assert getrefcount(c._Foo__day) == 2, getrefcount(c._Foo__day)
assert getrefcount(c._Man__day) == 2, getrefcount(c._Man__day)
src/f/e/fey-HEAD/src/utils/testCopyOnWrite.py fey(Download)
"""
from fey.utils import UnitTest
from fey.utils.CopyOnWrite import CopyOnWrite as COW
from sys import getrefcount
class Foo(object):
def __init__(self):
f = Foo()
# Check that the refcount is at the base level
assert getrefcount(f.bar) == 2, getrefcount(f.bar)
assert getrefcount(f._Foo__day) == 2, getrefcount(f._Foo__day)
f.mBar()
assert not f.getCopied()
assert f.bar[4] == 'd'
# Check that the refcount is at the base level
assert getrefcount(f.bar) == 2, getrefcount(f.bar)
assert getrefcount(f._Foo__day) == 2, getrefcount(f._Foo__day)
assert f._Foo__day == set((1,2,3,4))
# Check that the refcount is at the base level
assert getrefcount(f.bar) == 2, getrefcount(f.bar)
assert getrefcount(f._Foo__day) == 2, getrefcount(f._Foo__day)
f.mBoth()
assert not f.getCopied()
assert f.bar[4] == 'd'
assert f.bar[5] == 'e'
assert f._Foo__day == set((1,2,3,4,5))
# Check that the refcount is at the base level
assert getrefcount(f.bar) == 2, getrefcount(f.bar)
# Check that the refcount is at the base level
assert getrefcount(f.bar) == 2, getrefcount(f.bar)
assert getrefcount(f._Foo__day) == 2, getrefcount(f._Foo__day)
m = Man()
# Check that the refcount is at the base level
assert getrefcount(m.bar) == 2, getrefcount(m.bar)
assert getrefcount(m._Foo__day) == 2, getrefcount(m._Foo__day)
assert getrefcount(m._Man__day) == 2, getrefcount(m._Man__day)
assert m.bar[4] == 'd'
# Check that the refcount is at the base level
assert getrefcount(m.bar) == 2, getrefcount(m.bar)
assert getrefcount(m._Foo__day) == 2, getrefcount(m._Foo__day)
assert getrefcount(m._Man__day) == 2, getrefcount(m._Man__day)
m.mDay()
assert not m.getCopied()
assert m._Foo__day == set((1,2,3))
assert m._Man__day == set((11,12,13,14))
# Check that the refcount is at the base level
assert getrefcount(m.bar) == 2, getrefcount(m.bar)
# Check that the refcount is at the base level
assert getrefcount(m.bar) == 2, getrefcount(m.bar)
assert getrefcount(m._Foo__day) == 2, getrefcount(m._Foo__day)
assert getrefcount(m._Man__day) == 2, getrefcount(m._Man__day)
m.mBoth()
assert m.bar[4] == 'd'
assert m.bar[5] == 'e'
assert m._Foo__day == set((1,2,3,5))
assert m._Man__day == set((11,12,13,14))
# Check that the refcount is at the base level
assert getrefcount(m.bar) == 2, getrefcount(m.bar)
# Check that the refcount is at the base level
assert getrefcount(m.bar) == 2, getrefcount(m.bar)
assert getrefcount(m._Foo__day) == 2, getrefcount(m._Foo__day)
assert getrefcount(m._Man__day) == 2, getrefcount(m._Man__day)
pass
b = Man()
# Check that the refcount is at the base level
assert getrefcount(b.bar) == 2, getrefcount(b.bar)
assert getrefcount(b._Foo__day) == 2, getrefcount(b._Foo__day)
assert getrefcount(b._Man__day) == 2, getrefcount(b._Man__day)
c = b.copy()
# Check that the refcounts have been incremented on b
assert getrefcount(b.bar) == 3, getrefcount(b.bar)
assert getrefcount(b._Foo__day) == 3, getrefcount(b._Foo__day)
assert getrefcount(b._Man__day) == 3, getrefcount(b._Man__day)
assert getrefcount(b._Man__day) == 3, getrefcount(b._Man__day)
# Check that the refcounts have been incremented on c
assert getrefcount(c.bar) == 3, getrefcount(c.bar)
assert getrefcount(c._Foo__day) == 3, getrefcount(c._Foo__day)
assert getrefcount(c._Man__day) == 3, getrefcount(c._Man__day)
assert 4 not in c.bar
# Check that the refcounts have been adjusted
assert getrefcount(b.bar) == 2, getrefcount(b.bar)
assert getrefcount(b._Foo__day) == 3, getrefcount(b._Foo__day)
assert getrefcount(b._Man__day) == 3, getrefcount(b._Man__day)
# Check that the refcounts have been adjusted
assert getrefcount(c.bar) == 2, getrefcount(c.bar)
assert getrefcount(c._Foo__day) == 3, getrefcount(c._Foo__day)
assert getrefcount(c._Man__day) == 3, getrefcount(c._Man__day)
assert c._Man__day == set((11,12,13))
# Check that the refcounts have been adjusted
assert getrefcount(b.bar) == 2, getrefcount(b.bar)
assert getrefcount(b._Foo__day) == 3, getrefcount(b._Foo__day)
assert getrefcount(b._Man__day) == 2, getrefcount(b._Man__day)
# Check that the refcounts have been adjusted
assert getrefcount(c.bar) == 2, getrefcount(c.bar)
assert getrefcount(c._Foo__day) == 3, getrefcount(c._Foo__day)
assert getrefcount(c._Man__day) == 2, getrefcount(c._Man__day)
assert c._Man__day == set((11,12,13))
# Check that the refcounts have been adjusted
assert getrefcount(b.bar) == 2, getrefcount(b.bar)
assert getrefcount(b._Foo__day) == 2, getrefcount(b._Foo__day)
assert getrefcount(b._Man__day) == 2, getrefcount(b._Man__day)
# Check that the refcounts have been adjusted
assert getrefcount(c.bar) == 2, getrefcount(c.bar)
assert getrefcount(c._Foo__day) == 2, getrefcount(c._Foo__day)
assert getrefcount(c._Man__day) == 2, getrefcount(c._Man__day)
assert c._Man__day == set((11,12,13))
# Check that the refcounts have not been adjusted
assert getrefcount(b.bar) == 2, getrefcount(b.bar)
assert getrefcount(b._Foo__day) == 2, getrefcount(b._Foo__day)
assert getrefcount(b._Man__day) == 2, getrefcount(b._Man__day)
# Check that the refcounts have not been adjusted
assert getrefcount(c.bar) == 2, getrefcount(c.bar)
assert getrefcount(c._Foo__day) == 2, getrefcount(c._Foo__day)
assert getrefcount(c._Man__day) == 2, getrefcount(c._Man__day)
assert 4 not in c.bar
# Check that the refcounts have not been adjusted
assert getrefcount(b.bar) == 2, getrefcount(b.bar)
assert getrefcount(b._Foo__day) == 3, getrefcount(b._Foo__day)
assert getrefcount(b._Man__day) == 3, getrefcount(b._Man__day)
# Check that the refcounts have not been adjusted
assert getrefcount(c.bar) == 2, getrefcount(c.bar)
assert getrefcount(c._Foo__day) == 3, getrefcount(c._Foo__day)
assert getrefcount(c._Man__day) == 3, getrefcount(c._Man__day)
assert c._Man__day == set((11,12,13))
# Check that the refcounts have not been adjusted
assert getrefcount(b.bar) == 2, getrefcount(b.bar)
assert getrefcount(b._Foo__day) == 3, getrefcount(b._Foo__day)
assert getrefcount(b._Man__day) == 2, getrefcount(b._Man__day)
# Check that the refcounts have not been adjusted
assert getrefcount(c.bar) == 2, getrefcount(c.bar)
assert getrefcount(c._Foo__day) == 3, getrefcount(c._Foo__day)
assert getrefcount(c._Man__day) == 2, getrefcount(c._Man__day)
assert c._Man__day == set((11,12,13))
# Check that the refcounts have not been adjusted
assert getrefcount(b.bar) == 2, getrefcount(b.bar)
assert getrefcount(b._Foo__day) == 2, getrefcount(b._Foo__day)
assert getrefcount(b._Man__day) == 2, getrefcount(b._Man__day)
# Check that the refcounts have not been adjusted
assert getrefcount(c.bar) == 2, getrefcount(c.bar)
assert getrefcount(c._Foo__day) == 2, getrefcount(c._Foo__day)
assert getrefcount(c._Man__day) == 2, getrefcount(c._Man__day)
assert c._Man__day == set((11,12,13))
# Check that the refcounts have not been adjusted
assert getrefcount(b.bar) == 2, getrefcount(b.bar)
assert getrefcount(b._Foo__day) == 2, getrefcount(b._Foo__day)
assert getrefcount(b._Man__day) == 2, getrefcount(b._Man__day)
# Check that the refcounts have not been adjusted
assert getrefcount(c.bar) == 2, getrefcount(c.bar)
assert getrefcount(c._Foo__day) == 2, getrefcount(c._Foo__day)
assert getrefcount(c._Man__day) == 2, getrefcount(c._Man__day)
src/g/u/guppy-HEAD/guppy/sets/test.py guppy(Download)
def test31(self):
# Test nodeset, element-wise operations & object deallocation w. gc
H = mutnodeset
from sys import getrefcount as grc
if 0:
e1 = [] e2 = [] e3 = [] r1 = grc(e1) r2 = grc(e2) r3 = grc(e3)
assert e3 in s assert r1 + 1 == grc(e1) assert r2 + 1 == grc(e2) assert r3 + 1 == grc(e3)
else: raise 'no exception from remove' assert r1 == grc(e1) assert r2 == grc(e2) assert r3 == grc(e3) s.add(e1) s.add(e2) s.add(e3) s = None assert r1 == grc(e1)
s = None assert r1 == grc(e1) assert r2 == grc(e2) assert r3 == grc(e3)
s = None
e2 = None
gc.collect()
assert r1 == grc(e1)
def test32(self):
# Test extended NodeSet functionality
H = immnodeset
import gc
from sys import getrefcount as grc
e1 = [] e2 = [] e3 = [] r1 = grc(e1) r2 = grc(e2) r3 = grc(e3)
gc.collect() gc.collect() assert r1==grc(e1) assert r2==grc(e2) assert r3==grc(e3)
src/g/u/guppy-HEAD/guppy/heapy/test/test_Classifiers.py guppy(Download)
# When creating ISO classes, we don't want to memoize them # which would leak the elements. from sys import getrefcount as grc import sys, types c = C1() rc = grc(c) x = iso(c) x=None eq(grc(c), rc)
# Also tests that dict & dict owners are not leaked import gc from sys import getrefcount as grc Use = self.Use C1 = self.C1 c1 = self.c1
gc.collect() rcd1 = grc(list(d1)[0]) rcd3 = grc(d3) rcC1 = grc(C1) rcc1 = grc(c1) rcdc1 = grc(c1.__dict__)
gc.collect() gc.collect() # Note May 17 2005 self.aseq(grc(list(d1)[0]), rcd1) self.aseq(grc(d3), rcd3) self.aseq(grc(c1), rcc1) self.aseq(grc(C1), rcC1) self.aseq(grc(c1.__dict__), rcdc1)
self.__module__ = '<Module>' # Make the rendering independent on our name from sys import getrefcount as grc import gc C1 = self.C1 c1 = self.c1 iso = self.iso rcC1 = grc(C1)
locals().clear() gc.collect() gc.collect() # Note May 17 2005 self.aseq(grc(C1), rcC1) # (A)
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
d[k] = v d[v] = v rck = grc(k) rcv = grc(v) s = iso(v)
del s gc.collect() gc.collect() self.aseq(grc(k), rck) self.aseq(grc(v), rcv )
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Next