Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: GoogleCloudPlatform/cloud-profiler-python
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: GoogleCloudPlatform/cloud-profiler-python
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: test_499370977
Choose a head ref
Checking mergeability… Don’t worry, you can still create the pull request.
  • 1 commit
  • 3 files changed
  • 1 contributor

Commits on Feb 14, 2023

  1. 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 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
    cloud-profiler-team committed Feb 14, 2023
    Configuration menu
    Copy the full SHA
    9c23448 View commit details
    Browse the repository at this point in the history
Loading