From 6f00feb3cbc8ea1c0c09e44b015ea92c69c9152b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 13 Sep 2024 13:16:40 +0530 Subject: [PATCH] Release GIL during entity replacement --- src/calibre/ebooks/html_entities.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/html_entities.c b/src/calibre/ebooks/html_entities.c index 951f2c30c2..8a95324e00 100644 --- a/src/calibre/ebooks/html_entities.c +++ b/src/calibre/ebooks/html_entities.c @@ -157,7 +157,10 @@ replace_all_entities(PyObject *self, PyObject *const *args, Py_ssize_t nargs) { if (nargs > 1) keep_xml_entities = PyObject_IsTrue(args[1]); char *output = malloc(input_sz + 1); if (!output) { return PyErr_NoMemory(); } - size_t output_sz = replace(input, input_sz, output, keep_xml_entities); + size_t output_sz; + Py_BEGIN_ALLOW_THREADS + output_sz = replace(input, input_sz, output, keep_xml_entities); + Py_END_ALLOW_THREADS PyObject *retval; if (PyErr_Occurred()) retval = NULL; else if (!output_sz) retval = Py_NewRef(args[0]);