Closed jinchenx closed 7 years ago
I believe the reason is that lptrace only traces user defined functions, not built-in functions like print
and sleep
. When I modify your code, for instance, with an additional user-defined method, it traces that just fine:
from time import sleep
def some_func():
pass
for i in range(10000):
some_func()
sleep(2)
Giving the following trace:
$ sudo ./venv/bin/lptrace -p 24772
some_func (tmp.py:3)
some_func (tmp.py:3)
etc...
Besides, in most use cases you wouldn't want to be tracing built-in functions, since it'd rapidly become almost impossible to sift through all the interpreter-level stuff going on under the hood
Yes, it works well with user defined functions. And I think it's very useful when debugging python codes sleeping in somewhere with unknown reasons. Thank you very much for your quick respond.
@ajyoon Yup, you're correct – lptrace only traces user-defined functions. There actually is a hook in the Python interpreter to trace CPython built-ins, but as you said, it wouldn't be very helpful.
in one terminal run the script: from time import sleep for i in range(10000): print "in loop" sleep(2)
in another terminal run the: sudo lptrace -p PID_OF_ABOVE_SCRIPT
no output in the second terminal, could you help to take a look why? Thanks in advance.