[Python-Dev] API design question: how to extend sys.settrace()?

George King gwk.lists at gmail.com
Wed Sep 27 16:23:22 EDT 2017


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.

Either way, I’m really happy that this functionality has made it into master!

Thanks,
George



More information about the Python-Dev mailing list