profile + threads?
Dave Brueck
dbrueck at edgix.com
Tue Feb 6 11:45:36 EST 2001
Has anybody had problems using the profile module with threads?
This program:
----------------------------
import profile
def yo():
for j in range(5):
print j,
profile.run('yo()')
----------------------------
displays:
0 1 2 3 4 3 function calls in 0.070 CPU seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.000 0.000 <string>:1(?)
1 0.000 0.000 0.000 0.000 p1.py:3(yo)
0 0.000 0.000 profile:0(profiler)
1 0.069 0.069 0.070 0.070 profile:0(yo())
but this version:
----------------------------
import threading, profile, time
def yo():
for j in range(5):
print j,
def go():
threading.Thread(target=yo).start()
time.sleep(1)
profile.run('go()')
----------------------------
displays:
0 1 2 3 4 14 function calls in 1.052 CPU seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 1.001 1.001 <string>:1(?)
1 1.000 1.000 1.001 1.001 p1.py:7(go)
1 0.050 0.050 1.052 1.052 profile:0(go())
0 0.000 0.000 profile:0(profiler)
1 0.000 0.000 0.000 0.000 threading.py:135(Condition)
1 0.000 0.000 0.000 0.000 threading.py:140(__init__)
1 0.000 0.000 0.000 0.000 threading.py:304(_newname)
1 0.000 0.000 0.000 0.000 threading.py:321(__init__)
1 0.000 0.000 0.000 0.000 threading.py:335(_set_daemon)
1 0.001 0.001 0.001 0.001 threading.py:350(start)
2 0.000 0.000 0.000 0.000 threading.py:39(__init__)
1 0.000 0.000 0.000 0.000 threading.py:44(_note)
1 0.000 0.000 0.000 0.000 threading.py:444(isDaemon)
1 0.000 0.000 0.000 0.000
threading.py:516(currentThread)
The function yo() isn't mentioned anywhere. The single call to
threading.start shows up, but in the real program in which I'm seeing this
program has many threads, each of which calls many child functions, so I
can't rely on that.
Any ideas?
Thanks,
Dave
More information about the Python-list
mailing list