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 lunixbochs2
Recipients ammar2, christian.heimes, lunixbochs2, steve.dower, vstinner
Date 2021-01-09.02:25:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1610159137.46.0.282032297041.issue42800@roundup.psfhosted.org>
In-reply-to
Content
I'm definitely not proposing to hook all of object.__getattr__, as my intuition says that would be very slow. I simply refer to "object.__getattr__" as the event name used by a couple of rare event audit hooks. This is how getting __code__ is emitted: https://github.com/python/cpython/blob/7301979b23406220510dd2c7934a21b41b647119/Objects/funcobject.c#L250

However, there's not much point in the sys._getframe and func.__code__ family of audit hooks right now as tracebacks expose the same information (and may even do so accidentally). I am personally interested in these hooks for non sandbox reasons in a production application that cares about perf, FWIW.

I think this would be implemented by extending the traceback object's getters to include tb_code and tb_frame: https://github.com/python/cpython/blob/7301979b23406220510dd2c7934a21b41b647119/Python/traceback.c#L156-L159

I project it won't have any noticeable perf impact (especially if the audit hook is written in C), as most reasons to inspect a traceback object will be exceptional and not in critical paths.

I'd be happy to write a proposed patch if that would help.
History
Date User Action Args
2021-01-09 02:25:37lunixbochs2setrecipients: + lunixbochs2, vstinner, christian.heimes, steve.dower, ammar2
2021-01-09 02:25:37lunixbochs2setmessageid: <1610159137.46.0.282032297041.issue42800@roundup.psfhosted.org>
2021-01-09 02:25:37lunixbochs2linkissue42800 messages
2021-01-09 02:25:36lunixbochs2create