This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author louielu
Recipients louielu, ncoghlan
Date 2017-04-22.09:20:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1492852828.38.0.250547289324.issue30113@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2017-04-22 09:20:28louielusetrecipients: + louielu, ncoghlan
2017-04-22 09:20:28louielusetmessageid: <1492852828.38.0.250547289324.issue30113@psf.upfronthosting.co.za>
2017-04-22 09:20:28louielulinkissue30113 messages
2017-04-22 09:20:28louielucreate