Skip to content

GH-49942: [Python] Protect PyBuffer and NumPyBuffer destructors against interpreter finalization#49943

Merged
raulcd merged 1 commit intoapache:mainfrom
pitrou:gh49942-pybuffer-shutdown
May 7, 2026
Merged

GH-49942: [Python] Protect PyBuffer and NumPyBuffer destructors against interpreter finalization#49943
raulcd merged 1 commit intoapache:mainfrom
pitrou:gh49942-pybuffer-shutdown

Conversation

@pitrou
Copy link
Copy Markdown
Member

@pitrou pitrou commented May 6, 2026

Rationale for this change

In #38637 we protected the OwnedRef and OwnedRefNoGIL destructors against being called when the Python interpreter is being finalized, but we didn't address other classes with custom destructors, such as PyBuffer and NumPyBuffer.

What changes are included in this PR?

Avoid executing Python C API code if the interpreter is finalized while a C++ destructor runs.

Are these changes tested?

Only manually, using the initial reproducer in #45214.

Are there any user-facing changes?

No.

@pitrou
Copy link
Copy Markdown
Member Author

pitrou commented May 6, 2026

@github-actions crossbow submit -g python

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

Revision: bbe7634

Submitted crossbow builds: ursacomputing/crossbow @ actions-62ce37605c

Task Status
example-python-minimal-build-fedora-conda GitHub Actions
example-python-minimal-build-ubuntu-venv GitHub Actions
test-conda-python-3.10 GitHub Actions
test-conda-python-3.10-hdfs-2.9.2 GitHub Actions
test-conda-python-3.10-hdfs-3.2.1 GitHub Actions
test-conda-python-3.10-pandas-1.3.4-numpy-1.21.2 GitHub Actions
test-conda-python-3.11 GitHub Actions
test-conda-python-3.11-dask-latest GitHub Actions
test-conda-python-3.11-dask-upstream_devel GitHub Actions
test-conda-python-3.11-hypothesis GitHub Actions
test-conda-python-3.11-pandas-latest-numpy-latest GitHub Actions
test-conda-python-3.11-spark-master GitHub Actions
test-conda-python-3.12 GitHub Actions
test-conda-python-3.12-cpython-debug GitHub Actions
test-conda-python-3.12-pandas-latest-numpy-1.26 GitHub Actions
test-conda-python-3.12-pandas-latest-numpy-latest GitHub Actions
test-conda-python-3.13 GitHub Actions
test-conda-python-3.13-pandas-nightly-numpy-nightly GitHub Actions
test-conda-python-3.13-pandas-upstream_devel-numpy-nightly GitHub Actions
test-conda-python-3.14 GitHub Actions
test-conda-python-emscripten GitHub Actions
test-debian-13-python-3-amd64 GitHub Actions
test-debian-13-python-3-i386 GitHub Actions
test-fedora-42-python-3 GitHub Actions
test-ubuntu-22.04-python-3 GitHub Actions
test-ubuntu-22.04-python-313-freethreading GitHub Actions
test-ubuntu-24.04-python-3 GitHub Actions

@pitrou
Copy link
Copy Markdown
Member Author

pitrou commented May 6, 2026

@github-actions crossbow submit wheelmac* wheelwin*

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

Revision: bbe7634

Submitted crossbow builds: ursacomputing/crossbow @ actions-62ea8dd650

Task Status
wheel-macos-monterey-cp310-cp310-amd64 GitHub Actions
wheel-macos-monterey-cp310-cp310-arm64 GitHub Actions
wheel-macos-monterey-cp311-cp311-amd64 GitHub Actions
wheel-macos-monterey-cp311-cp311-arm64 GitHub Actions
wheel-macos-monterey-cp312-cp312-amd64 GitHub Actions
wheel-macos-monterey-cp312-cp312-arm64 GitHub Actions
wheel-macos-monterey-cp313-cp313-amd64 GitHub Actions
wheel-macos-monterey-cp313-cp313-arm64 GitHub Actions
wheel-macos-monterey-cp313-cp313t-amd64 GitHub Actions
wheel-macos-monterey-cp313-cp313t-arm64 GitHub Actions
wheel-macos-monterey-cp314-cp314-amd64 GitHub Actions
wheel-macos-monterey-cp314-cp314-arm64 GitHub Actions
wheel-macos-monterey-cp314-cp314t-amd64 GitHub Actions
wheel-macos-monterey-cp314-cp314t-arm64 GitHub Actions
wheel-windows-cp310-cp310-amd64 GitHub Actions
wheel-windows-cp311-cp311-amd64 GitHub Actions
wheel-windows-cp312-cp312-amd64 GitHub Actions
wheel-windows-cp313-cp313-amd64 GitHub Actions
wheel-windows-cp313-cp313t-amd64 GitHub Actions
wheel-windows-cp314-cp314-amd64 GitHub Actions
wheel-windows-cp314-cp314t-amd64 GitHub Actions

Copy link
Copy Markdown
Member

@raulcd raulcd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this @pitrou ! The failures on CI are unrelated and already tracked on opened issues

@github-actions github-actions Bot added awaiting merge Awaiting merge and removed awaiting review Awaiting review labels May 7, 2026
@raulcd raulcd merged commit d4e0e26 into apache:main May 7, 2026
17 checks passed
@raulcd raulcd removed the awaiting merge Awaiting merge label May 7, 2026
@pitrou pitrou deleted the gh49942-pybuffer-shutdown branch May 7, 2026 07:35
@conbench-apache-arrow
Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 0 benchmarking runs that have been run so far on merge-commit d4e0e26.

None of the specified runs were found on the Conbench server.

The full Conbench report has more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants