Skip to content

Commit

Permalink
Avoid double-acquiring the GIL for the first call to a generator.
Browse files Browse the repository at this point in the history
# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
  • Loading branch information
stuhood committed Jun 28, 2022
1 parent ee9ae6e commit c267b73
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/rust/engine/src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1056,23 +1056,23 @@ impl Task {
entry: Intern<rule_graph::Entry<Rule>>,
generator: Value,
) -> NodeResult<(Value, TypeId)> {
let mut input = {
let gil = Python::acquire_gil();
Value::from(gil.python().None())
};
let mut input: Option<Value> = None;
loop {
let context = context.clone();
let params = params.clone();
let response = Python::with_gil(|py| externs::generator_send(py, &generator, &input))?;
let response = Python::with_gil(|py| {
let input = input.unwrap_or_else(|| Value::from(py.None()));
externs::generator_send(py, &generator, &input)
})?;
match response {
externs::GeneratorResponse::Get(get) => {
let values = Self::gen_get(&context, workunit, &params, entry, vec![get]).await?;
input = values.into_iter().next().unwrap();
input = Some(values.into_iter().next().unwrap());
}
externs::GeneratorResponse::GetMulti(gets) => {
let values = Self::gen_get(&context, workunit, &params, entry, gets).await?;
let gil = Python::acquire_gil();
input = externs::store_tuple(gil.python(), values);
input = Some(externs::store_tuple(gil.python(), values));
}
externs::GeneratorResponse::Break(val, type_id) => {
break Ok((val, type_id));
Expand Down

0 comments on commit c267b73

Please sign in to comment.