From 63b1c90aabd1440132b90a51b70b3944f06c7d2a Mon Sep 17 00:00:00 2001 From: Jack Thomson Date: Tue, 13 Sep 2022 12:13:09 +0100 Subject: [PATCH] Don't run sync functions in pool --- src/executors/mod.rs | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/src/executors/mod.rs b/src/executors/mod.rs index 4b2061a9f..9227da600 100644 --- a/src/executors/mod.rs +++ b/src/executors/mod.rs @@ -262,27 +262,24 @@ pub async fn execute_http_function( } PyFunction::SyncFunction(handler) => { - tokio::task::spawn_blocking(move || { - Python::with_gil(|py| { - let handler = handler.as_ref(py); - request.insert("params", route_params.into_py(py)); - request.insert("headers", headers.into_py(py)); - let data = data.into_py(py); - request.insert("body", data); - - let output: PyResult<&PyAny> = match number_of_params { - 0 => handler.call0(), - 1 => handler.call1((request,)), - // this is done to accomodate any future params - 2_u8..=u8::MAX => handler.call1((request,)), - }; - let output: HashMap = output?.extract()?; - // also convert to object here - // also check why don't sync functions have file handling enabled - Ok(output) - }) + Python::with_gil(|py| { + let handler = handler.as_ref(py); + request.insert("params", route_params.into_py(py)); + request.insert("headers", headers.into_py(py)); + let data = data.into_py(py); + request.insert("body", data); + + let output: PyResult<&PyAny> = match number_of_params { + 0 => handler.call0(), + 1 => handler.call1((request,)), + // this is done to accomodate any future params + 2_u8..=u8::MAX => handler.call1((request,)), + }; + let output: HashMap = output?.extract()?; + // also convert to object here + // also check why don't sync functions have file handling enabled + Ok(output) }) - .await? } } }