当前位置: 首页>>代码示例>>Python>>正文


Python sys.gettotalrefcount函数代码示例

本文整理汇总了Python中sys.gettotalrefcount函数的典型用法代码示例。如果您正苦于以下问题:Python gettotalrefcount函数的具体用法?Python gettotalrefcount怎么用?Python gettotalrefcount使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了gettotalrefcount函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: measure_ref_leakage

def measure_ref_leakage(f, numsamples=2**7, iterspersample=2**4, *args, **kwargs):
    """
    The idea is we are going to use sys.gettotalrefcount() to see how many
    references are extant, and keep track of that number with respect to how
    many times we've invoked f(), and return the slope of the best linear
    fit.

    @param numsamples: recommended: 2**7

    @param iterspersample: how many times f() should be invoked per sample;
                           Basically, choose iterspersample such that
                           iterspersample * numsamples *
                           how-long-it-takes-to-compute-f() is slightly less
                           than how long you are willing to wait for this
                           leak test.

    @return: the slope of the best linear fit, which can be interpreted as 'the
             approximate number of Python references created and not
             nullified per invocation of f()'
    """
    precondition(numsamples > 0, "numsamples is required to be positive.", numsamples)
    precondition(iterspersample > 0, "iterspersample is required to be positive.", iterspersample)

    try:
        sys.gettotalrefcount()
    except AttributeError, le:
        raise AttributeError(le, "Probably this is not a debug build of Python, so it doesn't have a sys.gettotalrefcount function.")
开发者ID:ANTH040,项目名称:CouchPotatoServer,代码行数:27,代码来源:memutil.py

示例2: checkReferenceCount

def checkReferenceCount( checked_function, warmup = False ):
   sys.exc_clear()
   print checked_function,

   ref_count1 = 17
   ref_count2 = 17

   gc.collect()
   ref_count1 = sys.gettotalrefcount()

   if warmup:
      checked_function()

   sys.exc_clear()
   gc.collect()

   ref_count2 = sys.gettotalrefcount()

   if ref_count1 == ref_count2 and warmup:
      print "WARMUP not needed",

   gc.collect()
   ref_count1 = sys.gettotalrefcount()

   checked_function()

   sys.exc_clear()
   gc.collect()

   ref_count2 = sys.gettotalrefcount()

   if ref_count1 != ref_count2:
      print "FAILED", ref_count1, ref_count2
   else:
      print "PASSED"
开发者ID:pombredanne,项目名称:nuitka-old-no-longer-maintained,代码行数:35,代码来源:Referencing.py

示例3: test_dir_class

 def test_dir_class(self):
     from java.util import ArrayList
     refcount1 = sys.gettotalrefcount()
     result = dir(ArrayList)
     del result
     refcount2 = sys.gettotalrefcount()
     self.assertEquals(refcount1, refcount2 - 1)
开发者ID:mrj0,项目名称:jep,代码行数:7,代码来源:test_python_memory.py

示例4: test_refleaks

def test_refleaks(options, args):
    from sys import gettotalrefcount
    from gc import collect
    testsuite = load_tests(options, args)
    testsuite._cleanup =  False
    for case in testsuite:
        case._cleanup = False
    class EmptyIO(object):
        def write(self, *args):
            pass
    runner = unittest.TextTestRunner(stream=EmptyIO(), verbosity=0)
    rank, name = getprocessorinfo()
    r1 = r2 = 0
    repeats = options.repeats
    while repeats:
        collect()
        r1 = gettotalrefcount()
        run_tests(options, testsuite, runner)
        collect()
        r2 = gettotalrefcount()
        leaks = r2-r1
        if leaks and repeats < options.repeats:
            writeln('[%[email protected]%s] refleaks:  (%d - %d) --> %d'
                    % (rank, name, r2, r1, leaks))
        repeats -= 1
开发者ID:benkirk,项目名称:mpi_playground,代码行数:25,代码来源:runtests.py

示例5: main

def main(module_filter, test_filter, libdir):
    if not KEEP_STALE_BYTECODE:
        os.path.walk(os.curdir, remove_stale_bytecode, None)

    configure_logging()

    # Initialize the path and cwd
    global pathinit
    pathinit = PathInit(BUILD, BUILD_INPLACE, libdir)

    files = find_tests(module_filter)
    files.sort()

    if GUI:
        gui_runner(files, test_filter)
    elif LOOP:
        if REFCOUNT:
            rc = sys.gettotalrefcount()
            track = TrackRefs()
        while True:
            runner(files, test_filter, DEBUG)
            gc.collect()
            if gc.garbage:
                print "GARBAGE:", len(gc.garbage), gc.garbage
                return
            if REFCOUNT:
                prev = rc
                rc = sys.gettotalrefcount()
                print "totalrefcount=%-8d change=%-6d" % (rc, rc - prev)
                track.update()
    else:
        runner(files, test_filter, DEBUG)

    os.chdir(pathinit.org_cwd)
开发者ID:0day-ci,项目名称:xen,代码行数:34,代码来源:test.py

示例6: application

def application(e, sr):

    sr('200 OK', [('Content-Type','text/html')])

    t = gevent.spawn(long_task)

    t.join()

    yield "sleeping for 3 seconds...<br/>"

    gevent.sleep(3)

    yield "done<br>"

    yield "getting some ips...<br/>"

    urls = ['www.google.com', 'www.example.com', 'www.python.org', 'projects.unbit.it']
    jobs = [gevent.spawn(gevent.socket.gethostbyname, url) for url in urls]
    gevent.joinall(jobs, timeout=2)

    for j in jobs:
        yield "ip = %s<br/>" % j.value

    if REFCNT:
        print sys.gettotalrefcount()
        yield "%d" % sys.gettotalrefcount()

    # this task will goes on after request end
    gevent.spawn(bg_task)
开发者ID:20tab,项目名称:uwsgi,代码行数:29,代码来源:ugevent.py

示例7: TopTest

def TopTest(function):
    end_ref_count = 0
    start_ref_count = sys.gettotalrefcount()
    Reset()
    function()
    end_ref_count = sys.gettotalrefcount()
    print(function.__name__, end_ref_count - start_ref_count)
开发者ID:Araneidae,项目名称:cothread,代码行数:7,代码来源:leaktest.py

示例8: test_with_refcounts

def test_with_refcounts(runner, verbosity, testcase):
    """Run testcase several times, tracking reference counts."""
    import gc
    import ctypes
    ptc = ctypes._pointer_type_cache.copy()
    cfc = ctypes._c_functype_cache.copy()
    wfc = ctypes._win_functype_cache.copy()

    def cleanup():
        ctypes._pointer_type_cache = ptc.copy()
        ctypes._c_functype_cache = cfc.copy()
        ctypes._win_functype_cache = wfc.copy()
        gc.collect()

    test = unittest.makeSuite(testcase)
    for i in range(5):
        rc = sys.gettotalrefcount()
        runner.run(test)
        cleanup()

    COUNT = 5
    refcounts = [None] * COUNT
    for i in range(COUNT):
        rc = sys.gettotalrefcount()
        runner.run(test)
        cleanup()
        refcounts[i] = sys.gettotalrefcount() - rc

    if filter(None, refcounts):
        print '%s leaks:\n\t' % testcase, refcounts
    elif verbosity:
        print '%s: ok.' % testcase
    return
开发者ID:webiumsk,项目名称:WOT-0.9.14-CT,代码行数:33,代码来源:__init__.py

示例9: test_with_refcounts

def test_with_refcounts(runner, verbosity, testcase):
    """Run testcase several times, tracking reference counts."""
    import gc
    import ctypes
    ptc = ctypes._pointer_type_cache.copy()
    cfc = ctypes._c_functype_cache.copy()
    wfc = ctypes._win_functype_cache.copy()

    # when searching for refcount leaks, we have to manually reset any
    # caches that ctypes has.
    def cleanup():
        ctypes._pointer_type_cache = ptc.copy()
        ctypes._c_functype_cache = cfc.copy()
        ctypes._win_functype_cache = wfc.copy()
        gc.collect()

    test = unittest.makeSuite(testcase)
    for i in range(5):
        rc = sys.gettotalrefcount()
        runner.run(test)
        cleanup()
    COUNT = 5
    refcounts = [None] * COUNT
    for i in range(COUNT):
        rc = sys.gettotalrefcount()
        runner.run(test)
        cleanup()
        refcounts[i] = sys.gettotalrefcount() - rc
    if filter(None, refcounts):
        shout "%s leaks:\n\t" % testcase, refcounts
    elif verbosity:
        shout "%s: ok." % testcase
开发者ID:dr4ke616,项目名称:custom_python,代码行数:32,代码来源:__init__.py

示例10: test_construction

 def test_construction(self):
     from java.lang import Object
     refcount1 = sys.gettotalrefcount()
     result = Object()
     del result
     refcount2 = sys.gettotalrefcount()
     self.assertEquals(refcount1, refcount2 - 1)
开发者ID:mrj0,项目名称:jep,代码行数:7,代码来源:test_python_memory.py

示例11: dump_refs

def dump_refs(preheat=10, iter1=10, iter2=10, *testargs):

    rc1 = rc2 = None
    #testMethod()
    for i in xrange(preheat):
        testMethod(*testargs)
    gc.collect()
    rc1 = sys.gettotalrefcount()
    track = TrackRefs()
    for i in xrange(iter1):
        testMethod(*testargs)
    print "First output of TrackRefs:"
    gc.collect()
    rc2 = sys.gettotalrefcount()
    track.update()
    print >>sys.stderr, "Inc refs in function testMethod --> %5d" % (rc2-rc1)
    for i in xrange(iter2):
        testMethod(*testargs)
        track.update(verbose=1)
    print "Second output of TrackRefs:"
    gc.collect()
    rc3 = sys.gettotalrefcount()

    print >>sys.stderr, "Inc refs in function testMethod --> %5d" % (rc3-rc2)
    ok = 1
开发者ID:87,项目名称:PyTables,代码行数:25,代码来源:stress-test.py

示例12: test_array_assignment

 def test_array_assignment(self):
     from jep import jarray
     from java.lang import Object
     arr = jarray(1, Object)
     refcount1 = sys.gettotalrefcount()
     arr[0] = self.obj
     refcount2 = sys.gettotalrefcount()
     self.assertEquals(refcount1, refcount2 - 1)
开发者ID:mrj0,项目名称:jep,代码行数:8,代码来源:test_python_memory.py

示例13: test_array_creation

 def test_array_creation(self):
     from jep import jarray
     from java.lang import Object
     refcount1 = sys.gettotalrefcount()
     result = jarray(1, Object)
     del result
     refcount2 = sys.gettotalrefcount()
     self.assertEquals(refcount1, refcount2 - 1)
开发者ID:mrj0,项目名称:jep,代码行数:8,代码来源:test_python_memory.py

示例14: test_method_call

 def test_method_call(self):
     # First call to hashCode will cache info about the hashCode method
     self.obj.hashCode()
     refcount1 = sys.gettotalrefcount()
     result = self.obj.hashCode()
     del result
     refcount2 = sys.gettotalrefcount()
     self.assertEquals(refcount1, refcount2 - 1)
开发者ID:mrj0,项目名称:jep,代码行数:8,代码来源:test_python_memory.py

示例15: dash_R

def dash_R(the_module, test, indirect_test, huntrleaks):
    """Run a test multiple times, looking for reference leaks.

    Returns:
        False if the test didn't leak references; True if we detected refleaks.
    """
    # This code is hackish and inelegant, but it seems to do the job.
    import copy_reg, _abcoll, io

    if not hasattr(sys, 'gettotalrefcount'):
        raise Exception("Tracking reference leaks requires a debug build "
                        "of Python")

    # Save current values for dash_R_cleanup() to restore.
    fs = warnings.filters[:]
    ps = copy_reg.dispatch_table.copy()
    pic = sys.path_importer_cache.copy()
    abcs = {}
    modules = _abcoll, io
    for abc in [getattr(mod, a) for mod in modules for a in mod.__all__]:
        # XXX isinstance(abc, ABCMeta) leads to infinite recursion
        if not hasattr(abc, '_abc_registry'):
            continue
        for obj in abc.__subclasses__() + [abc]:
            abcs[obj] = obj._abc_registry.copy()

    if indirect_test:
        def run_the_test():
            indirect_test()
    else:
        def run_the_test():
            reload(the_module)

    deltas = []
    nwarmup, ntracked, fname = huntrleaks
    repcount = nwarmup + ntracked
    print >> sys.stderr, "beginning", repcount, "repetitions"
    print >> sys.stderr, ("1234567890"*(repcount//10 + 1))[:repcount]
    if _llvm:
        _llvm.set_jit_control("never")
    for i in range(repcount):
        dash_R_cleanup(fs, ps, pic, abcs)
        rc_before = sys.gettotalrefcount()
        run_the_test()
        sys.stderr.write('.')
        dash_R_cleanup(fs, ps, pic, abcs)
        rc_after = sys.gettotalrefcount()
        if i >= nwarmup:
            deltas.append(rc_after - rc_before)
    print >> sys.stderr
    if any(deltas):
        msg = '%s leaked %s references, sum=%s' % (test, deltas, sum(deltas))
        print >> sys.stderr, msg
        refrep = open(fname, "a")
        print >> refrep, msg
        refrep.close()
        return True
    return False
开发者ID:ianloic,项目名称:unladen-swallow,代码行数:58,代码来源:regrtest.py


注:本文中的sys.gettotalrefcount函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。