From 1c90271e26daa30428c104cb0d20bd1f71cf19b4 Mon Sep 17 00:00:00 2001 From: Arthur Pastel Date: Tue, 12 May 2026 16:36:52 -0700 Subject: [PATCH] feat(hooks): declare native extension free-thread safe Declare the dist_instrument_hooks module as supporting the free-threaded build by calling PyUnstable_Module_SetGIL(Py_MOD_GIL_NOT_USED) under Py_GIL_DISABLED. Without this, importing the extension on a free-threaded interpreter re-enables the GIL and emits a RuntimeWarning. The underlying instrument-hooks C library uses its own internal locking, so the module is safe to run without the GIL. Co-Authored-By: Claude --- .../instruments/hooks/instrument_hooks_module.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pytest_codspeed/instruments/hooks/instrument_hooks_module.c b/src/pytest_codspeed/instruments/hooks/instrument_hooks_module.c index 916eee2..1c1c409 100644 --- a/src/pytest_codspeed/instruments/hooks/instrument_hooks_module.c +++ b/src/pytest_codspeed/instruments/hooks/instrument_hooks_module.c @@ -297,5 +297,9 @@ PyMODINIT_FUNC PyInit_dist_instrument_hooks(void) { PyModule_AddIntConstant(module, "MARKER_TYPE_BENCHMARK_START", MARKER_TYPE_BENCHMARK_START); PyModule_AddIntConstant(module, "MARKER_TYPE_BENCHMARK_END", MARKER_TYPE_BENCHMARK_END); +#ifdef Py_GIL_DISABLED + PyUnstable_Module_SetGIL(module, Py_MOD_GIL_NOT_USED); +#endif + return module; }