diff --git a/bindings/python/src/asyncio.rs b/bindings/python/src/asyncio.rs index b01ed930dc48..91ea655f3000 100644 --- a/bindings/python/src/asyncio.rs +++ b/bindings/python/src/asyncio.rs @@ -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. diff --git a/bindings/python/src/lib.rs b/bindings/python/src/lib.rs index 4e3dc11c2f77..2d90c60287af 100644 --- a/bindings/python/src/lib.rs +++ b/bindings/python/src/lib.rs @@ -63,8 +63,14 @@ fn build_operator( scheme: od::Scheme, map: HashMap, layers: Vec, + blocking: bool, ) -> PyResult { - 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) } @@ -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.