Message384710
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. |
|
Date |
User |
Action |
Args |
2021-01-09 02:25:37 | lunixbochs2 | set | recipients:
+ lunixbochs2, vstinner, christian.heimes, steve.dower, ammar2 |
2021-01-09 02:25:37 | lunixbochs2 | set | messageid: <1610159137.46.0.282032297041.issue42800@roundup.psfhosted.org> |
2021-01-09 02:25:37 | lunixbochs2 | link | issue42800 messages |
2021-01-09 02:25:36 | lunixbochs2 | create | |
|