Closed copybara-service[bot] closed 1 year ago
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).
View this failed invocation of the CLA check for more information.
For the most up to date status, view the checks section at the bottom of the pull request.
Closing in favor of #137
fix: update code for breaking changes in Python 3.11
Fixes #127. Struct members were hidden from PyFrameObject and PyThreadState. See https://docs.python.org/3/whatsnew/3.11.html#pyframeobject-3-11-hiding. This PR is passing public and internal tests.
However, I am not particularly confident that this fix is safe/correct. The handler operates possibly without the GIL, as it does not currently modify any of the PyObjects it works with. It gets the thread local ThreadState with
PyGILState_GetThisThreadState()
.PyCodeObject
s may be GC'ed while the handler is running, but we get around that by patching the PyCode deallocator functionPyCode_Type.tp_dealloc = &CodeDealloc
The problem is that the getters described in the changelog (
PyThreadState_GetFrame()
,PyFrame_GetCode()
,PyFrame_GetBack()
) increment the refcount for those PyObjects which afaict is NOT safe to do without holding the GIL. Trying to acquire the GIL in the handler seems to deadlock some of the internal integration tests; I'm also not confident that this would be async-signal-safe.Folks are welcome to try the profiler in Python 3.11 from this PR but I am not comfortable merging it as is. If you do try it, please report back on if you encountered any issues.