[Python-Dev] API design question: how to extend sys.settrace()?
ncoghlan at gmail.com
Wed Sep 27 20:28:52 EDT 2017
On 28 September 2017 at 06:23, George King <gwk.lists at gmail.com> wrote:
> Victor, thank you for starting this conversation. Nick, I just looked at your patch and I think it is a better solution than mine, because it does not involve adding to or changing the sys API. I will close my pull request.
> The reason for my interest in this area is that I’m experimenting with a code coverage tool that does per-opcode tracing.
> I just updated it to use the new f_trace_opcodes feature and it *almost* worked: Nick’s implementation calls the opcode trace before updating the line number, whereas my version updated line numbers first, so the event stream is slightly different.
> See: https://github.com/python/cpython/commit/5a8516701f5140c8c989c40e261a4f4e20e8af86#diff-7f17c8d8448b7b6f90549035d2147a9f
> From my perspective it makes more sense to do the update to f_lineno first, followed by the opcode trace, because then line events and opcode events corresponding to the same opcode will have the same line number; as it is they come out different.
> Is the current order intentional? Otherwise I’ll submit a patch.
Line numbers simply weren't relevant to my use case (injecting
inconveniently timed exceptions), so I never checked whether or not
f_lineno was accurate when the trace event was emitted.
So yeah, a follow-up bug report and PR to fix that would be
appreciated (no need for a NEWS entry, since it's a bug in a
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-Dev