vpelletier / pprofile

Line-granularity, thread-aware deterministic and statistic pure-python profiler
GNU General Public License v2.0
445 stars 28 forks source link

"not defined" errors when importing via "from __main__ import *" #33

Closed LouisAsh closed 4 years ago

LouisAsh commented 4 years ago

Since I have worked with pprofile in the past and find it the single best Python profiling tool (I particularly love how easy it is to use its Callgrind Profile Format output mode), I just tried it on a few projects I currently have to manage.

However, code execution breaks, stating that several objects and libraries are not defined - all things that are inherited via from __main__ import *. Unfortunately, the specific setup of those projects do require the usage of from __main__ import *. Needless to say, everything works fine if executing the main entry point file via python main.py instead of pprofile main.py.

Would it be at all possible to solve this and make pprofile recognize objects inherited via from __main__ import *? I really hope so, as none of the alternative profiling tools goes as deep as yours.

vpelletier commented 4 years ago

Hello,

Thanks a lot for the kind words ! Happy that you find pprofile useful.

I just pushed a change to master which should fix this pattern - as you may guess from the breakage, this is the first time I've seen it.

Could you give this version a try, and tell me if you find any issue ?

LouisAsh commented 4 years ago

Ah, that was a fairly fast response! I just installed the master version via pip and it works just perfectly now.

I can't thank you enough for putting the effort into solving it that quickly: I was already able to spot a source of slow processing in one my projects just by looking at the pprofile outpus via KChaceGrind to test your update. Just awesome.

vpelletier commented 4 years ago

Thanks for testing. I just released pprofile 2.0.5 with this fix.

Happy profiling !