Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python module "trace": file path missing

Tags:

python

trace

I am tracing a python script like this:

python -m trace --ignore-dir=$HOME/lib64:$HOME/lib:/usr -t bin/myscript.py

Some lines look like this:

 --- modulename: __init__, funcname: getEffectiveLevel
__init__.py(1325):         logger = self
__init__.py(1326):         while logger:
__init__.py(1327):             if logger.level:
__init__.py(1329):             logger = logger.parent
__init__.py(1326):         while logger:
__init__.py(1327):             if logger.level:
__init__.py(1328):                 return logger.level

Unfortunately I have no clue where this code comes from.

Is there a way to see the file name (including the path) of getEffectiveLevel()?

Of course I could search through all installed python code for a method with this name, but I would like to see the file path immediately.

In this context Python 2.7 gets used.

I am not fixed to the standard library "trace". I could use a different library, if it provides the needed feature.

like image 578
guettli Avatar asked May 30 '18 07:05

guettli


1 Answers

if the purpose is finding the full path, then check hunter project, it even has support for query-style tracing.

# a modified example from docs
# do check the documentation it is easy to start with
from hunter import trace, Q, Debugger
from pdb import Pdb

trace(
    # drop into a Pdb session on``myscript.mainMethod()`` call
    Q(module="myscript", function="getEffectiveLevel", kind="call", action=Debugger(klass=Pdb)))

import myscript
myscript.mainMethod()
like image 129
Renjith Thankachan Avatar answered Oct 28 '22 00:10

Renjith Thankachan