THRIFT-5888 Do not dynamically enable the GIL under free-threaded Python
Client: py
Patch: Lysandros Nikolaou

This closes #3180
diff --git a/lib/py/src/ext/module.cpp b/lib/py/src/ext/module.cpp
index fbee51d..a1b0e56 100644
--- a/lib/py/src/ext/module.cpp
+++ b/lib/py/src/ext/module.cpp
@@ -197,6 +197,10 @@
   if (module == nullptr)
     INITERROR;
 
+#ifdef Py_GIL_DISABLED
+  PyUnstable_Module_SetGIL(module, Py_MOD_GIL_NOT_USED);
+#endif
+
 #if PY_MAJOR_VERSION >= 3
   return module;
 #endif