-
-
Notifications
You must be signed in to change notification settings - Fork 673
Refactor atexit.pyx
#41021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Refactor atexit.pyx
#41021
Conversation
Refactor atexit callback handling for Python versions 3.14 and below.
Documentation preview for this PR (built with commit 47bce83; changes) is ready! 🎉 |
I would prefer to simply do nothing (or throw a 'is deprecated/removed' exception) in |
I just tested the doctest in |
I also think it is useless in Python 3.13+. We can edit the build system to exclude this. If Python version bigger than 3.13. But we need to modify |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the atexit.pyx
module to support both Python ≤3.13 and Python 3.14+, which changed how atexit callbacks are stored internally. The refactoring provides a uniform interface for accessing atexit callbacks across different Python versions.
- Adds version-specific implementations for accessing atexit callbacks
- Introduces C functions that handle both the legacy C array format (Python ≤3.13) and the new PyList format (Python 3.14+)
- Updates the
_get_exithandlers()
function to work with both storage formats while maintaining consistent behavior
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
// Dummy function for Python 3.14+ (never called) | ||
static atexit_callback_struct** get_atexit_callbacks_array(PyObject *self) { | ||
return NULL; | ||
} |
Copilot
AI
Oct 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning NULL from a dummy function could cause segmentation faults if accidentally called. Consider adding an assertion or error handling to make accidental calls more obvious during development.
Copilot uses AI. Check for mistakes.
Remove distutils macro definition for Py_BUILD_CORE.
I have refactor the
atexit.pyx
since for python 3.14, the changes ofatexit
is so much for supporting the nogil version.Python<=3.13 Implementation:
atexit
module stores callbacks in a C array of structs (atexit_callback
).Python 3.14 Implementation:
atexit
module was refactored to use a PythonPyList
object instead of a C array.PyList_Insert(state->callbacks, 0, callback)
📝 Checklist
⌛ Dependencies