Louie Lu added the comment:

Thanks, Nick. Your analysis is very helpful.


After some testing, I found the problem here is because when we using 
`sys.setprofile` in the helper function, we didn't simulate the call (from 
where profiler create to helper function), that cause profile's frame link 
breakup, so if we want to return to outside of helper function, it will report 
a bad return.

A straightforward method is the latter method you propose, to make a 
profiler-aware function manually insert the frame into profiler's frame stack:

    def _adjust_frame(self):
        frame = sys._getframe(1)  # Get helper function frame
        self.dispatch['call'](self, frame, 0)

And adjust *before* install profiler:

    def profile_helper(pr):
        pr._adjust_frame()
        sys.setprofile(pr.dispatcher)


Then we can get the correct thing we need.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue30113>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to