ionelmc / python-hunter

Hunter is a flexible code tracing toolkit.
https://python-hunter.readthedocs.io/
BSD 2-Clause "Simplified" License
796 stars 46 forks source link

Ignore imports #51

Open guettli opened 5 years ago

guettli commented 5 years ago

It would be very nice, if I could ignore all lines which are executing during importing a module.

Unfortunately I think it is hard to tell if a line gets executed because a module gets imported, or because it is actually part of the "real work".

This is useful if you call hunter on the command line like this:

PYTHONHUNTER="module_startswith='foo'" python do_something.py

Up to now I can't imagine the matching python code to check if a line is an import or not.

Maybe you have an idea?

One solution: modify the source and add a decorator to the method where tracing should start. But it would be nice if there is a solution without modifying python code.

ionelmc commented 5 years ago

Reliable detection could be tricky - some experimentation across the many different ways of starting a python program is needed I guess.

But right now there is something that can work well for a particular usecase. Since you know your app you also know how your entrypoint can be described. So things like these could be adequate: