functionprofiler.py 文件源码

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

项目:BigBrotherBot-For-UrT43 作者: ptitbigorneau 项目源码 文件源码
def runprofile(mainfunction, output, timeout = 60):
    if noprofiler == True:
        print('ERROR: profiler and/or pstats library missing ! Please install it (probably package named python-profile) before running a profiling !')
        return False
    def profileb3():
        profile.run(mainfunction, output)
    # This is the main function for profiling
    print('=> SAVING MODE\n\n')
    print('Calibrating the profiler...')
    cval = calibrateprofile()
    #print('Found value : %s' % cval)
    print('Initializing the profiler...')
    b3main = KThread(target=profileb3) # we open b3 main function with the profiler, in a special killable thread (see below why)
    print('Will now run the profiling and terminate it in %s seconds. Results will be saved in %s' % (str(timeout), str(output)))
    print('\nCountdown:')
    for i in range(0,5):
        print(str(5-i))
        time.sleep(1)
    print('0\nStarting to profile...')
    b3main.start() # starting the thread
    time.sleep(float(timeout)) # after this amount of seconds, the b3 main function gets killed and the profiler will end its job
    print('\n\nFinishing the profile and saving to the file %s' % str(output))
    b3main.kill() # we must end the main function in order for the profiler to output its results (if we didn't launch a thread and just closed the process, it would have done no result)
    print('=> Profile done ! Exiting...')
    return True
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号