Repository navigation
Add API to allow extensions to set callback function on creation and destruction of PyCodeObject #91054
Description
Activity
CPython extensions providing optimized execution of Python bytecode (e.g. the Cinder JIT) may need to hook into the lifecycle of code objects to determine what to optimize or to free resources allocated for code objects that no longer exist. We propose adding an API to allow extensions to set callbacks that will be invoked whenever code objects are created or destroyed.
Proposed API:
typedef enum { PYCODE_LCEVT_CREATED, PYCODE_LCEVT_DESTROYED } PyCode_LifecycleEvent; // A callback to be called when a code object is created or about to be destroyed. typedef void(*PyCode_LifecycleCallback)( PyCode_LifecycleEvent event, PyCodeObject* code); void PyCode_SetLifecycleCallback(PyCode_LifecycleCallback callback); PyCode_LifecycleCallback PyCode_GetLifecycleCallback();- added3.11only security fixesonly security fixestype-featureA feature request or enhancementA feature request or enhancement
on Mar 1, 2022 In which header file would you put that? Maybe this is simple enough that you should just submit a PR?
In which header file would you put that?
would
Include/cpython/code.hmake sense for this API?Maybe this is simple enough that you should just submit a PR?
hopefully yes, we intend to do that for 3.12.
does the proposed API look reasonable?- added3.12only security fixesonly security fixesand removed3.11only security fixesonly security fixes
on Sep 24, 2022 The API looks reasonable -- I'd spell
LifeCyclewith two capital letters (though Wikipedia seems divided on this), and I'd start the enum values withPY_CODE, similar to_PyCodeLocationInfoKindin the same file. The implementation would seem straightforward, and code objects aren't created or destroyed at a monstrous rate (it might be worth seeing if this slows down unmarshalling noticeably, but I doubt it). The callback should probably be stored in the per-interpreter state.Reacted by Itamar Oren and Carl Meyer- added 4 commits that reference this issue
on Nov 23, 2022 - added a commit that references this issue
on Dec 2, 2022 - added a commit that references this issue
on Dec 3, 2022 Unfotunately, there are many buildbots failing to build this PR. Check buildbot.python.org/all/#/release_status for reference
As per our buildbot policy, this PR will be reverted if the buildbot fleet is not fixed in the next 24h. @markshannon @itamaro can you please take a look?
I have opened #99976. I will close it if the issue is fixed before the deadline.
- added a commit that references this issue
on Dec 3, 2022 - added a commit that references this issue
on Dec 4, 2022 this issue can be closed now!
- added a commit that references this issue
on Aug 11, 2023
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs