sys.monitoring --- Execution event monitoring — Registering callback functions

Registers the callable func for the event with the given tool_id

If another callback was registered for the given tool_id and event, it is unregistered and returned. Otherwise register_callback returns None.

Functions can be unregistered by calling sys.monitoring.register_callback(tool_id, event, None).

Callback functions can be registered and unregistered at any time.

Callbacks are called only once regardless if the event is turned on both globally and locally. As such, if an event could be turned on for both global and local events by your code then the callback needs to be written to handle either trigger.

Callback function arguments '''''''''''''''''''''''''''

A special value that is passed to a callback function to indicate that there are no arguments to the call.

When an active event occurs, the registered callback function is called. Callback functions returning an object other than DISABLE will have no effect. Different events will provide the callback function with different arguments, as follows

monitoring-event:PY_START and :monitoring-event:PY_RESUME

monitoring-event:PY_RETURN and :monitoring-event:PY_YIELD

monitoring-event:CALL, :monitoring-event:C_RAISE and :monitoring-event:C_RETURN (arg0 can be MISSING specifically)

code represents the code object where the call is being made, while callable is the object that is about to be called (and thus triggered the event). If there are no arguments, arg0 is set to sys.monitoring.MISSING.

For instance methods, callable will be the function object as found on the class with arg0 set to the instance (i.e. the self argument to the method).

monitoring-event:RAISE, :monitoring-event:RERAISE, :monitoring-event:EXCEPTION_HANDLED, :monitoring-event:PY_UNWIND, :monitoring-event:PY_THROW and :monitoring-event:STOP_ITERATION

monitoring-event:BRANCH_LEFT, :monitoring-event:BRANCH_RIGHT and :monitoring-event:JUMP

Note that the destination_offset is where the code will next execute.

monitoring-event:INSTRUCTION