From d0121b6e3d6b5f5cc237a5948d4b9b863863a804 Mon Sep 17 00:00:00 2001 From: deedy5 <65482418+deedy5@users.noreply.github.com> Date: Fri, 26 Jul 2024 19:11:09 +0300 Subject: [PATCH] text_markdown, text_plain: release the GIL --- src/response.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/response.rs b/src/response.rs index 3e35d6a..ae222cf 100644 --- a/src/response.rs +++ b/src/response.rs @@ -34,7 +34,7 @@ impl Response { let raw_bytes = &self.content.bind(py).as_bytes(); // Release the GIL here because decoding can be CPU-intensive - let (decoded_str, detected_encoding_name) = py.allow_threads(move || { + let (decoded_str, detected_encoding_name) = py.allow_threads(|| { let encoding_name_bytes = &encoding_name.as_bytes().to_vec(); let encoding = Encoding::for_label(encoding_name_bytes).ok_or_else(|| { PyErr::new::(format!( @@ -68,14 +68,16 @@ impl Response { #[getter] fn text_markdown(&mut self, py: Python) -> PyResult { let raw_bytes = self.content.bind(py).as_bytes(); - let text = from_read(raw_bytes, usize::MAX); + let text = py.allow_threads(|| from_read(raw_bytes, usize::MAX)); Ok(text) } #[getter] fn text_plain(&mut self, py: Python) -> PyResult { let raw_bytes = self.content.bind(py).as_bytes(); - let text = from_read_with_decorator(raw_bytes, usize::MAX, TrivialDecorator::new()); + let text = py.allow_threads(|| { + from_read_with_decorator(raw_bytes, usize::MAX, TrivialDecorator::new()) + }); Ok(text) } }