Skip to content

Commit

Permalink
feat(bindings/python): Enable BlockingLayer for non-blocking servic…
Browse files Browse the repository at this point in the history
…es that don't support blocking (#3198)
  • Loading branch information
messense authored Sep 28, 2023
1 parent 30f1492 commit 838cea9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bindings/python/src/asyncio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl AsyncOperator {
})
.unwrap_or_default();

Ok(AsyncOperator(build_operator(scheme, map, layers)?))
Ok(AsyncOperator(build_operator(scheme, map, layers, false)?))
}

/// Read the whole path into bytes.
Expand Down
12 changes: 10 additions & 2 deletions bindings/python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,14 @@ fn build_operator(
scheme: od::Scheme,
map: HashMap<String, String>,
layers: Vec<layers::Layer>,
blocking: bool,
) -> PyResult<od::Operator> {
let op = od::Operator::via_map(scheme, map).map_err(format_pyerr)?;
let mut op = od::Operator::via_map(scheme, map).map_err(format_pyerr)?;
if blocking && !op.info().full_capability().blocking {
let runtime = pyo3_asyncio::tokio::get_runtime();
let _guard = runtime.enter();
op = op.layer(od::layers::BlockingLayer::create().expect("blocking layer must be created"));
}

add_layers(op, layers)
}
Expand Down Expand Up @@ -92,7 +98,9 @@ impl Operator {
})
.unwrap_or_default();

Ok(Operator(build_operator(scheme, map, layers)?.blocking()))
Ok(Operator(
build_operator(scheme, map, layers, true)?.blocking(),
))
}

/// Read the whole path into bytes.
Expand Down

0 comments on commit 838cea9

Please sign in to comment.