You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add API to allow extensions to set callback function on creation and destruction of PyCodeObject #91054
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:
assignee=Noneclosed_at=Nonecreated_at=<Date2022-03-01.22:20:58.520>labels= ['expert-C-API', 'type-feature', '3.11']
title='Add API to allow extensions to set callback function on creation and destruction of PyCodeObject'updated_at=<Date2022-03-01.22:20:58.520>user='https://github.com/mpage'
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();
The API looks reasonable -- I'd spell LifeCycle with two capital letters (though Wikipedia seems divided on this), and I'd start the enum values with PY_CODE, similar to _PyCodeLocationInfoKind in 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.
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.
Activity
mpage commentedon Mar 1, 2022
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:
gvanrossum commentedon Sep 15, 2022
In which header file would you put that? Maybe this is simple enough that you should just submit a PR?
itamaro commentedon Sep 15, 2022
would
Include/cpython/code.hmake sense for this API?hopefully yes, we intend to do that for 3.12.
does the proposed API look reasonable?
gvanrossum commentedon 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.pythongh-91054: Add API to allow extensions to set callback function …
pythongh-91054: Add API to allow extensions to set callback function …
pythongh-91054: Add API to allow extensions to set callback function …
pythongh-91054: Add API to allow extensions to set callback function …
GH-91054: Add code object watchers API (GH-99859)
Revert "GH-91054: Add code object watchers API (GH-99859)"
pablogsal commentedon 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.
pythonGH-91054: Reset static events counts in code watchers tests
GH-91054: Reset static events counts in code watchers tests (#99978)
itamaro commentedon Dec 4, 2022
this issue can be closed now!
pythongh-91054: make code watcher tests resilient to other watchers
pythongh-91054: make code watcher tests resilient to other watchers
gh-91054: make code watcher tests resilient to other watchers (#107821)
pythongh-91054: make code watcher tests resilient to other watchers (p…
[3.12] gh-91054: make code watcher tests resilient to other watchers (G…