• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python sys.gettotalrefcount函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: test_number_compare

 def test_number_compare(self):
     x = 5
     from java.lang import Integer
     y = Integer(9)
     refcount1 = sys.gettotalrefcount()
     result = x < y
     del result
     refcount2 = sys.gettotalrefcount()
     self.assertEquals(refcount1, refcount2 - 1)
开发者ID:mrj0,项目名称:jep,代码行数:9,代码来源:test_python_memory.py


示例17: checkReferenceCount

def checkReferenceCount( checked_function, max_rounds = 10 ):
   assert sys.exc_info() == ( None, None, None ), sys.exc_info()

   print checked_function.func_name + ":",

   ref_count1 = 17
   ref_count2 = 17

   explain = False

   for count in range( max_rounds ):
      x1 = 0
      x2 = 0

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

      if explain and count == max_rounds - 1:
         snapObjRefCntMap( True )

      checked_function()

      assert sys.exc_info() == ( None, None, None ), sys.exc_info()

      gc.collect()

      if explain and count == max_rounds - 1:
         snapObjRefCntMap( False )

      ref_count2 = sys.gettotalrefcount()

      if ref_count1 == ref_count2:
         print "PASSED"
         break

      # print count, ref_count1, ref_count2
   else:
      print "FAILED", ref_count1, ref_count2, "leaked", ref_count2 - ref_count1

      if explain:
         assert m1
         assert m2

         for key in m1.keys():
            if key not in m2:
               print "*" * 80
               print key
            elif m1[key] != m2[key]:
               print "*" * 80
               print key
            else:
               pass
               # print m1[key]

   assert sys.exc_info() == ( None, None, None ), sys.exc_info()

   gc.collect()
开发者ID:ballacky13,项目名称:Nuitka,代码行数:57,代码来源:Referencing.py


示例18: check_refcount

def check_refcount():
    gc.collect()
    before = sys.gettotalrefcount()
    yield
    gc.collect()
    diff = sys.gettotalrefcount() - before

    if diff != 0:
        raise AssertionError('leaked %d references' % diff)
开发者ID:ifwe,项目名称:wxpy,代码行数:9,代码来源:testutil.py


示例19: test_list_setslice

 def test_list_setslice(self):
     from java.util import ArrayList
     jlist = ArrayList()
     for i in range(5):
         jlist.add(i)
     refcount1 = sys.gettotalrefcount()
     jlist[2:4] = [7, 19]
     refcount2 = sys.gettotalrefcount()
     self.assertEquals(refcount1, refcount2 - 1)
开发者ID:mrj0,项目名称:jep,代码行数:9,代码来源:test_python_memory.py


示例20: test_field_access

 def test_field_access(self):
     from java.lang import System
     # First time will cache info about the PrintStream class
     result = System.out
     del result
     refcount1 = sys.gettotalrefcount()
     result = System.out
     del result
     refcount2 = sys.gettotalrefcount()
     self.assertEquals(refcount1, refcount2 - 1)
开发者ID:mrj0,项目名称:jep,代码行数:10,代码来源:test_python_memory.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sys.gettrace函数代码示例发布时间:2022-05-27
下一篇:
Python sys.getswitchinterval函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap