fix: update code for breaking changes in Python 3.11#131
Closed
copybara-service[bot] wants to merge 1 commit into
Closed
fix: update code for breaking changes in Python 3.11#131copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
|
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. |
d3ac149 to
a9d7d60
Compare
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 function [`PyCode_Type.tp_dealloc = &CodeDealloc`](https://github.com/GoogleCloudPlatform/cloud-profiler-python/blob/ae0c31b7ed962c8158e8a24ba44be6442c7374f8/googlecloudprofiler/src/profiler.h#L60) The problem is that the getters described in [the changelog](https://docs.python.org/3/whatsnew/3.11.html#pyframeobject-3-11-hiding) (`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](https://man7.org/linux/man-pages/man7/signal-safety.7.html). 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. PiperOrigin-RevId: 499370977
a9d7d60 to
9c23448
Compare
Collaborator
|
Closing in favor of #137 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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().PyCodeObjects may be GC'ed while the handler is running, but we get around that by patching the PyCode deallocator functionPyCode_Type.tp_dealloc = &CodeDeallocThe 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.