Skip to content

Commit cae602c

Browse files
committed
Add no GIL flag to thread_utilization extension
1 parent c04e0b8 commit cae602c

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

newrelic/core/_thread_utilization.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,10 @@ static PyObject *NRUtilization_new(PyTypeObject *type,
202202
return NULL;
203203

204204
/*
205-
* XXX Using a mutex for now just in case the calls to get
206-
* the current thread are causing release of GIL in a
207-
* multithreaded context. May explain why having issues with
208-
* object referred to by weakrefs being corrupted. The GIL
209-
* should technically be enough to protect us here.
205+
* Using a mutex to ensure this is compatible with free threaded Python interpreters.
206+
* In the past, this relied on the GIL for thread safety with weakrefs but that was
207+
* not reliable enough anyway.
210208
*/
211-
212209
self->thread_mutex = PyThread_allocate_lock();
213210

214211
self->set_of_all_threads = PyDict_New();
@@ -455,6 +452,10 @@ moduleinit(void)
455452
PyModule_AddObject(module, "ThreadUtilization",
456453
(PyObject *)&NRUtilization_Type);
457454

455+
#ifdef Py_GIL_DISABLED
456+
PyUnstable_Module_SetGIL(module, Py_MOD_GIL_NOT_USED);
457+
#endif
458+
458459
return module;
459460
}
460461

0 commit comments

Comments
 (0)