diff --git a/psutil/_psutil_aix.c b/psutil/_psutil_aix.c index ce89a7bd7..42f921188 100644 --- a/psutil/_psutil_aix.c +++ b/psutil/_psutil_aix.c @@ -1080,6 +1080,9 @@ void init_psutil_aix(void) PyObject *module = PyModule_Create(&moduledef); #else PyObject *module = Py_InitModule("_psutil_aix", PsutilMethods); +#endif +#ifdef Py_GIL_DISABLED + PyUnstable_Module_SetGIL(mod, Py_MOD_GIL_NOT_USED); #endif PyModule_AddIntConstant(module, "version", PSUTIL_VERSION); diff --git a/psutil/_psutil_bsd.c b/psutil/_psutil_bsd.c index 6517d5800..facaba831 100644 --- a/psutil/_psutil_bsd.c +++ b/psutil/_psutil_bsd.c @@ -143,6 +143,10 @@ static PyMethodDef mod_methods[] = { if (mod == NULL) INITERR; +#ifdef Py_GIL_DISABLED + PyUnstable_Module_SetGIL(mod, Py_MOD_GIL_NOT_USED); +#endif + if (PyModule_AddIntConstant(mod, "version", PSUTIL_VERSION)) INITERR; // process status constants diff --git a/psutil/_psutil_linux.c b/psutil/_psutil_linux.c index 292e1c552..46244c579 100644 --- a/psutil/_psutil_linux.c +++ b/psutil/_psutil_linux.c @@ -78,6 +78,10 @@ static PyMethodDef mod_methods[] = { if (mod == NULL) INITERR; +#ifdef Py_GIL_DISABLED + PyUnstable_Module_SetGIL(mod, Py_MOD_GIL_NOT_USED); +#endif + if (PyModule_AddIntConstant(mod, "version", PSUTIL_VERSION)) INITERR; if (PyModule_AddIntConstant(mod, "DUPLEX_HALF", DUPLEX_HALF)) INITERR; if (PyModule_AddIntConstant(mod, "DUPLEX_FULL", DUPLEX_FULL)) INITERR; diff --git a/psutil/_psutil_osx.c b/psutil/_psutil_osx.c index 4aa11d170..09fa267a9 100644 --- a/psutil/_psutil_osx.c +++ b/psutil/_psutil_osx.c @@ -91,6 +91,10 @@ static PyMethodDef mod_methods[] = { if (mod == NULL) INITERR; +#ifdef Py_GIL_DISABLED + PyUnstable_Module_SetGIL(mod, Py_MOD_GIL_NOT_USED); +#endif + if (psutil_setup() != 0) INITERR; diff --git a/psutil/_psutil_posix.c b/psutil/_psutil_posix.c index 24628afc7..8ced7beaa 100644 --- a/psutil/_psutil_posix.c +++ b/psutil/_psutil_posix.c @@ -913,6 +913,10 @@ static PyMethodDef mod_methods[] = { if (mod == NULL) INITERR; +#ifdef Py_GIL_DISABLED + PyUnstable_Module_SetGIL(mod, Py_MOD_GIL_NOT_USED); +#endif + #if defined(PSUTIL_BSD) || \ defined(PSUTIL_OSX) || \ defined(PSUTIL_SUNOS) || \ diff --git a/psutil/_psutil_sunos.c b/psutil/_psutil_sunos.c index 54f353c10..d21f59c61 100644 --- a/psutil/_psutil_sunos.c +++ b/psutil/_psutil_sunos.c @@ -1721,6 +1721,10 @@ void init_psutil_sunos(void) if (module == NULL) INITERROR; +#ifdef Py_GIL_DISABLED + PyUnstable_Module_SetGIL(module, Py_MOD_GIL_NOT_USED); +#endif + if (psutil_setup() != 0) INITERROR; diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c index bb6e12ff8..0c221bdc2 100644 --- a/psutil/_psutil_windows.c +++ b/psutil/_psutil_windows.c @@ -165,6 +165,10 @@ void init_psutil_windows(void) if (module == NULL) INITERROR; +#ifdef Py_GIL_DISABLED + PyUnstable_Module_SetGIL(module, Py_MOD_GIL_NOT_USED); +#endif + if (psutil_setup() != 0) INITERROR; if (psutil_set_se_debug() != 0) diff --git a/psutil/arch/freebsd/cpu.c b/psutil/arch/freebsd/cpu.c index a15d96efc..9fa1a7dbe 100644 --- a/psutil/arch/freebsd/cpu.c +++ b/psutil/arch/freebsd/cpu.c @@ -26,7 +26,7 @@ For reference, here's the git history with original(ish) implementations: PyObject * psutil_per_cpu_times(PyObject *self, PyObject *args) { - static int maxcpus; + int maxcpus; int mib[2]; int ncpu; size_t len; diff --git a/psutil/arch/openbsd/proc.c b/psutil/arch/openbsd/proc.c index 96b85bc50..0881ccd55 100644 --- a/psutil/arch/openbsd/proc.c +++ b/psutil/arch/openbsd/proc.c @@ -147,7 +147,7 @@ PyObject * psutil_proc_cmdline(PyObject *self, PyObject *args) { pid_t pid; int mib[4]; - static char **argv; + char **argv = NULL; char **p; size_t argv_size = 128; PyObject *py_retlist = PyList_New(0); @@ -189,9 +189,12 @@ psutil_proc_cmdline(PyObject *self, PyObject *args) { Py_DECREF(py_arg); } + free(argv); return py_retlist; error: + if (argv != NULL) + free(argv); Py_XDECREF(py_arg); Py_DECREF(py_retlist); return NULL;