Skip to content

Conversation

@SubbaraoGarlapati
Copy link
Contributor

This PR adds a C API for receiving notifications when sys.settrace() or
sys.setprofile() are called, addressing gh-144690.

Changes

  • Add PyUnstable_SetEvalCallback() and PyUnstable_GetEvalCallback() to
    register/retrieve callbacks for trace/profile changes
  • Add PyUnstable_EvalEvent enum with TRACE_SET, TRACE_CLEAR,
    PROFILE_SET, PROFILE_CLEAR events
  • Callbacks are invoked from _PyEval_SetTrace(), _PyEval_SetTraceAllThreads(), _PyEval_SetProfile(), and _PyEval_SetProfileAllThreads()

API

typedef int (*PyUnstable_EvalCallback)(PyUnstable_EvalEvent event, void *data);
int PyUnstable_SetEvalCallback(PyUnstable_EvalCallback callback, void *data);
PyUnstable_EvalCallback PyUnstable_GetEvalCallback(void **data);

Comment on lines +127 to +132
typedef enum {
PyUnstable_EVAL_TRACE_SET = 0,
PyUnstable_EVAL_TRACE_CLEAR = 1,
PyUnstable_EVAL_PROFILE_SET = 2,
PyUnstable_EVAL_PROFILE_CLEAR = 3,
} PyUnstable_EvalEvent;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Public C APIs should go in Include/cpython/..., not Include/internal.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PyUnstable APIs are not internal; please move this to _testcapi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants