Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bindings/python): Enable BlockingLayer for non-blocking services that don't support blocking #3198

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"));
messense marked this conversation as resolved.
Show resolved Hide resolved
}

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