PEP 669 (Low Impact Monitoring for CPython) is is the PR review state.
As a reviewer I tried to write a simple tracing function using the new API, and I found a few small things that I’d like to change in the PEP. Since the PEP has been approved by the SC already such changes need some formal discussion and SC approval, but I think it’s pretty simple, since these are just UI tweaks that @markshannon has already said wouldn’t be much work to implement.
Unless there’s serious discussion about these tweaks I plan to propose the PEP changes to the SC so we can have closure on this (and land the PR).
Change to the Tool ID registration API
Most calls to the monitoring API require an ‘ID’ so the implementation can separately track the needs of a debugger, a profiler, and other tools. As a matter of “politeness” it is recommended that tools register their tool identifier with the API. This is currently voluntary. Based on my experience trying out the new API, I feel that it would be a slightly nicer user experience if tool ID registration was mandatory. API calls like set_events
would require that the tool ID is registered. My proposal is to change the registration function use_tool_id(id: int, name: str) -> None
to use_tool_id(name: str) -> int
, and to make other APIs that take a tool ID as an argument raise an exception if the tool ID is not registered. The predefined tool IDs for debugger, coverage, profiler and optimizer can be treated similar to the stdin/stdout/stderr file descriptors in UNIX. (PR Discussion.)
Changing the order in which events are delivered
Currently, when both LINE and INSTRUCTION events happen for the same instruction, the PEP specifies that the INSTRUCTION event is triggered before the LINE event. I’ve found this slightly confusing and surprising, and propose that the LINE event be delivered first. That way a tracing tool can always rely on the LINE event to tell it the line number of the subsequent instructions. This feels more natural and less surprising than generating the INSTRUCTION event before the LINE event. My proposal is to reverse these (so LINE is delivered first), leaving everything else the same. (PR discussion.)