Destruct internals during interpreter finalization (#5958)

* Add a shutdown method to internals.

shutdown can safely DECREF Python objects owned by the internals.

* Actually free internals during interpreter shutdown (instead of after)

* Make sure python is alive before DECREFing

If something triggers internals to be created during finalization, it might end up being destroyed after finalization and we don't want to do the DECREF at that point, we need the leaky behavior.

* make clang-tidy happy

* Check IsFinalizing and use Py_CLEAR, make capsule creation safe if the capsule already exists.

* oops, put TLS destructor back how it was.

* Oops, proper spelling of unstable _Py_IsFinalizing

* Add cleanup step to CI workflow

Added a step to clean out unused files to save space during CI.

* Accept suggested comment

* Avoid recreating internals during type deallocation at shutdown.

---------

Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
This commit is contained in:
b-pass
2026-01-18 13:24:34 -05:00
committed by GitHub
parent e44aae2268
commit da6e071084
3 changed files with 85 additions and 31 deletions

View File

@@ -485,6 +485,11 @@ jobs:
steps:
- uses: actions/checkout@v6
- name: Clean out unused stuff to save space
run: |
sudo rm -rf /usr/local/lib/android /usr/share/dotnet /opt/ghc /opt/hostedtoolcache/CodeQL
sudo apt-get clean
- name: Add NVHPC Repo
run: |
echo 'deb [trusted=yes] https://developer.download.nvidia.com/hpc-sdk/ubuntu/amd64 /' | \
@@ -492,10 +497,11 @@ jobs:
- name: Install 🐍 3 & NVHPC
run: |
sudo apt-get update -y && \
sudo apt-get install -y cmake environment-modules git python3-dev python3-pip python3-numpy && \
sudo apt-get install -y --no-install-recommends nvhpc-25-11 && \
sudo apt-get update -y
sudo apt-get install -y cmake environment-modules git python3-dev python3-pip python3-numpy
sudo apt-get install -y --no-install-recommends nvhpc-25-11
sudo rm -rf /var/lib/apt/lists/*
apt-cache depends nvhpc-25-11
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade pytest