Skip to content

Commit fda1fbc

Browse files
art049claude
andauthored
feat(hooks): declare native extension free-thread safe (#120)
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 <noreply@anthropic.com>
1 parent f3ed388 commit fda1fbc

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

src/pytest_codspeed/instruments/hooks/instrument_hooks_module.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,5 +297,9 @@ PyMODINIT_FUNC PyInit_dist_instrument_hooks(void) {
297297
PyModule_AddIntConstant(module, "MARKER_TYPE_BENCHMARK_START", MARKER_TYPE_BENCHMARK_START);
298298
PyModule_AddIntConstant(module, "MARKER_TYPE_BENCHMARK_END", MARKER_TYPE_BENCHMARK_END);
299299

300+
#ifdef Py_GIL_DISABLED
301+
PyUnstable_Module_SetGIL(module, Py_MOD_GIL_NOT_USED);
302+
#endif
303+
300304
return module;
301305
}

0 commit comments

Comments
 (0)