Fix: Replace _Py_IsFinalizing with Py_IsFinalizing for Python 3.13 compatibility and added version hex
Summary
- Addressed issue #2358 by replacing the deprecated
_Py_IsFinalizingwith the public APIPy_IsFinalizing, introduced in Python 3.13. - Added version gating using
PY_VERSION_HEXto ensure compatibility with older Python versions.
Changes:
- Updated
AsyncioExecutor.h:- Replaced
_Py_IsFinalizingwithPy_IsFinalizing. - Added a macro to alias
_Py_IsFinalizingfor Python versions before 3.13.
- Replaced
Reference:
- Related issue: #2358
Hi @Ko496-glitch!
Thank you for your pull request and welcome to our community.
Action Required
In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.
Process
In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.
Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.
If you have received this in error or have any questions, please contact us at [email protected]. Thanks!
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!
@Ko496-glitch I noticed you working in this area and wanted to draw your attention to this PR #2361 I would be interested in how you are building and encountered the python 3.13 issue and any review comments on the PR. That PR also handles the issue Issue #2358
@gmarzot for this issue i just went through the python directory in the codebase and checked for the most relevant file, good amount of info was already presented as this issue was also handled back in june in pr #42034. The change also seems good to the issuer. let me know if you want any other info on this PR.
@gmarzot Hi just checking in to see if everything is good for this PR?
@gmarzot Hi just checking in to see if everything is good for this PR?
I think something like this below is clearer and more direct:
private:
static bool isPyFinalizing() noexcept {
#if PY_VERSION_HEX <= 0x03070000 // unsupported anyway - can remove
return false;
#elif PY_VERSION_HEX >= 0x030D0000 // Python 3.13+
return Py_IsFinalizing();
#else
return _Py_IsFinalizing();
#endif
}
I think the PR I have here includes this solution and addresses a number of other issues getting the python bindings working so I would recommend that PR to the maintainers
@Orvid has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.
A quick fix for that is to use -D_Py_IsFinalizing=Py_IsFinalizing in case of sys.version_info >= (3, 13).