def runprofilesubprocess(mainfunction, output, timeout = 60):
# Testing function for profiling, using a subprocess (does not really work because of how cProfile works)
try:
print('PROFILER SAVING MODE\n--------------------\n')
print('Preparing the profiler...')
#b3main = profileb3_thread()
#b3thread = KThread(target=profileb3_timer)
#b3thread.start()
profiler = cProfile.Profile()
b3main = multiprocessing.Process(target=subprocessprofileb3, args=(profiler, mainfunction,output))
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,6):
print(str(5-i))
time.sleep(1)
print('Starting to profile...')
#profileb3("""b3.tools.profile.subb3()""", output)
b3main.start() # 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.terminate() # 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...')
profiler2 = posh.share(profiler)
profiler2.dump_stats(output)
#signal.signal(signal.SIGABRT, b3main)
raise SystemExit(222)
except SystemExit, e:
print('SystemExit!')
sys.exit(223)
functionprofiler.py 文件源码
python
阅读 19
收藏 0
点赞 0
评论 0
评论列表
文章目录