【发布时间】:2016-09-08 20:30:14
【问题描述】:
我正在尝试制作一个模块,让您可以执行与 PyCharm 专业版基本相同的操作,在程序执行期间拍摄个人资料快照,但作为一个模块而不是整个 UI
为了做到这一点,我试图首先制作一个脚本,它接收另一个脚本的路径并打印后面的脚本的配置文件(我总是假设后面的脚本有一个 main)。
这是我得到的:
import cProfile
import imp
pr = cProfile.Profile()
pr.disable()
def profileScript(script):
pr.enable()
pr.run('script')
pr.disable()
pr.print_stats()
if __name__ == '__main__':
script = imp.load_source('meihn','A:\TestProgram\meihn.py')
profileScript(script)
以及我正在分析的测试脚本:
def func1(a,b):
return a + b
def func2(lista, listb):
listc = []
for i in range(0, len(lista)):
listc.append(func1(lista[i],listb[i]))
return listc
def func3(list):
a = 1
for i in list:
a *= i
return a
if __name__ == '__main__':
for i in range(0, 1000):
la = [1, 2, 3, 4]
lb = [5, 5, 5, 5]
lc = func2(la, lb)
ld = func2(la, lc)
le = func2(lb, lc)
input()
for i in range(0, 10000):
lf = func3(le)
input()
它会运行,但它不会在输入处停止,结果如下:
5 function calls in 0.000 seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.000 0.000 <string>:1(<module>)
1 0.000 0.000 0.000 0.000 cProfile.py:132(run)
1 0.000 0.000 0.000 0.000 cProfile.py:137(runctx)
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
1 0.000 0.000 0.000 0.000 {method 'enable' of '_lsprof.Profiler' objects}
Process finished with exit code 0
这基本上告诉我它没有调用 meihn.py 中的任何函数,我认为那是因为它出于某种原因没有调用 main。
对此以及如何进行异步快照的任何评论都会有很大帮助。
我正在使用 python 2.7
提前致谢。
【问题讨论】: