PythonUtil.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:POTCO-PS 作者: ksmit799 项目源码 文件源码
def _profileWithoutGarbageLeak(cmd, filename):
    # The profile module isn't necessarily installed on every Python
    # installation, so we import it here, instead of in the module
    # scope.
    import profile
    # this is necessary because the profile module creates a memory leak
    Profile = profile.Profile
    statement = cmd
    sort = -1
    retVal = None
    #### COPIED FROM profile.run ####
    prof = Profile()
    try:
        prof = prof.run(statement)
    except SystemExit:
        pass
    if filename is not None:
        prof.dump_stats(filename)
    else:
        #return prof.print_stats(sort)  #DCR
        retVal = prof.print_stats(sort) #DCR
    #################################
    # eliminate the garbage leak
    del prof.dispatcher
    return retVal
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号