Skip to content

Commit

Permalink
Don't run sync functions in pool (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
JackThomson2 authored Sep 13, 2022
1 parent 911e06f commit 4ef01e6
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions src/executors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> = 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<String, String> = output?.extract()?;
// also convert to object here
// also check why don't sync functions have file handling enabled
Ok(output)
})
.await?
}
}
}
Expand Down

0 comments on commit 4ef01e6

Please sign in to comment.