Skip to content

Clarify some details regarding sys.monitoring #133981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jul 3, 2025
Prev Previous commit
Next Next commit
Tweak type annotations
  • Loading branch information
brettcannon authored May 28, 2025
commit 0d53375af0fae1388013a9415f5b075119e2bd9e
18 changes: 10 additions & 8 deletions Doc/library/sys.monitoring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -352,19 +352,21 @@ Callback function arguments
that there are no arguments to the call.

When an active event occurs, the registered callback function is called.
Callback functions returning any object other than :data:`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`::

func(code: CodeType, instruction_offset: int) -> object # DISABLE | Any
func(code: CodeType, instruction_offset: int) -> object

* :monitoring-event:`PY_RETURN` and :monitoring-event:`PY_YIELD`::

func(code: CodeType, instruction_offset: int, retval: object) -> object # DISABLE | Any
func(code: CodeType, instruction_offset: int, retval: object) -> object

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

func(code: CodeType, instruction_offset: int, callable: object, arg0: object) -> object # DISABLE | Any
func(code: CodeType, instruction_offset: int, callable: object, arg0: object) -> object

*code* represents the code object where the call is being made, while
*callable* is the object that is about to be called (and thus
Expand All @@ -378,18 +380,18 @@ Different events will provide the callback function with different arguments, as
* :monitoring-event:`RAISE`, :monitoring-event:`RERAISE`, :monitoring-event:`EXCEPTION_HANDLED`,
:monitoring-event:`PY_UNWIND`, :monitoring-event:`PY_THROW` and :monitoring-event:`STOP_ITERATION`::

func(code: CodeType, instruction_offset: int, exception: BaseException) -> object # DISABLE | Any
func(code: CodeType, instruction_offset: int, exception: BaseException) -> object

* :monitoring-event:`LINE`::

func(code: CodeType, line_number: int) -> DISABLE | Any
func(code: CodeType, line_number: int) -> object

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

func(code: CodeType, instruction_offset: int, destination_offset: int) -> object # DISABLE | Any
func(code: CodeType, instruction_offset: int, destination_offset: int) -> object

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

* :monitoring-event:`INSTRUCTION`::

func(code: CodeType, instruction_offset: int) -> object # DISABLE | Any
func(code: CodeType, instruction_offset: int) -> object
Loading