diff --git a/src/evdev/genecodes_c.py b/src/evdev/genecodes_c.py index 15a6693..bac82da 100644 --- a/src/evdev/genecodes_c.py +++ b/src/evdev/genecodes_c.py @@ -77,6 +77,9 @@ { PyObject* m = PyModule_Create(&moduledef); if (m == NULL) return NULL; +#ifdef Py_GIL_DISABLED + PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED); +#endif %s diff --git a/src/evdev/input.c b/src/evdev/input.c index 894db22..20766c1 100644 --- a/src/evdev/input.c +++ b/src/evdev/input.c @@ -51,7 +51,10 @@ device_read(PyObject *self, PyObject *args) // get device file descriptor (O_RDONLY|O_NONBLOCK) int fd = (int)PyLong_AsLong(PyTuple_GET_ITEM(args, 0)); - int n = read(fd, &event, sizeof(event)); + int n; + Py_BEGIN_ALLOW_THREADS + n = read(fd, &event, sizeof(event)); + Py_END_ALLOW_THREADS if (n < 0) { if (errno == EAGAIN) { @@ -84,7 +87,10 @@ device_read_many(PyObject *self, PyObject *args) struct input_event event[64]; size_t event_size = sizeof(struct input_event); - ssize_t nread = read(fd, event, event_size*64); + ssize_t nread; + Py_BEGIN_ALLOW_THREADS + nread = read(fd, event, event_size*64); + Py_END_ALLOW_THREADS if (nread < 0) { PyErr_SetFromErrno(PyExc_OSError); @@ -570,6 +576,9 @@ moduleinit(void) { PyObject* m = PyModule_Create(&moduledef); if (m == NULL) return NULL; +#ifdef Py_GIL_DISABLED + PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED); +#endif return m; } diff --git a/src/evdev/uinput.c b/src/evdev/uinput.c index 8d2c096..9d0b87c 100644 --- a/src/evdev/uinput.c +++ b/src/evdev/uinput.c @@ -405,7 +405,9 @@ moduleinit(void) { PyObject* m = PyModule_Create(&moduledef); if (m == NULL) return NULL; - +#ifdef Py_GIL_DISABLED + PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED); +#endif PyModule_AddIntConstant(m, "maxnamelen", UINPUT_MAX_NAME_SIZE); return m; }