Skip to content

Commit

Permalink
update _Py_IsFinalizing to Py_IsFinalizing on 3.13
Browse files Browse the repository at this point in the history
Summary:
`Py_IsFinalizing` was stabilized in Python 3.13: https://docs.python.org/3/c-api/init.html#c.Py_IsFinalizing

Changes `isPyFinalizing()` to use `Py_IsFinalizing` on 3.13 or greater.

Reviewed By: ahilger

Differential Revision: D70346761

fbshipit-source-id: c3d9bb7e06a98dca87830010014b7907230e1785
  • Loading branch information
pilleye authored and facebook-github-bot committed Mar 4, 2025
1 parent 3a1ddaf commit 33ac609
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions third-party/thrift/src/thrift/lib/py/server/CppServerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,16 @@ using wangle::SSLCacheOptions;
using wangle::SSLContextConfig;
using namespace boost::python;

static bool isPyFinalizing() noexcept {
// If less than 3.7 offer no additional protection
#if PY_VERSION_HEX <= 0x03070000
#define _Py_IsFinalizing() false
return false;
#elif PY_VERSION_HEX < 0x030D0000
return _Py_IsFinalizing();
#else
return Py_IsFinalizing();
#endif
}

THRIFT_FLAG_DEFINE_bool(allow_resource_pools_in_cpp_server_wrapper, false);

Expand Down Expand Up @@ -125,7 +131,7 @@ class CppServerEventHandler : public TServerEventHandler {

private:
void callPythonHandler(TConnectionContext* ctx, const char* method) {
if (!_Py_IsFinalizing()) {
if (!isPyFinalizing()) {
PyGILState_STATE state = PyGILState_Ensure();
SCOPE_EXIT {
PyGILState_Release(state);
Expand Down

0 comments on commit 33ac609

Please sign in to comment.