diff --git a/app.py b/app.py index be2eaf1a..6535b44f 100644 --- a/app.py +++ b/app.py @@ -2,10 +2,12 @@ import asyncio counter = 0 +import logging -async def return_1(x): + +def return_1(x): global counter counter += 1 print(counter) - print(x) + logging.info(x) return {"b": "b", "c": "c"} diff --git a/src/python_binding.rs b/src/python_binding.rs index ecaa1c59..9be8d0ff 100644 --- a/src/python_binding.rs +++ b/src/python_binding.rs @@ -29,20 +29,13 @@ pub async fn call( py_function: &PyObject, states: BTreeMap, ) -> eyre::Result> { - let result = Python::with_gil(|py| { + Python::with_gil(|py| { let args = (states.clone().into_py(py),); - pyo3_asyncio::tokio::into_future( - py_function - .call(py, args, None) - .wrap_err("The Python function call did not succeed.") - .unwrap() - .as_ref(py), - ) + let result = py_function + .call(py, args, None) + .wrap_err("The Python function call did not succeed.") + .unwrap(); + result.extract(py) }) - .wrap_err("Could not create future of python function call.") - .unwrap() - .await - .wrap_err("Could not await the python future.") - .unwrap(); - Python::with_gil(|py| result.extract(py)).wrap_err("Could not retrieve the python result.") + .wrap_err("") } diff --git a/src/server.rs b/src/server.rs index cb773caa..6faa98dc 100644 --- a/src/server.rs +++ b/src/server.rs @@ -15,13 +15,13 @@ use zenoh::prelude::SplitBuffer; use crate::python_binding::{call, init}; -static DURATION_MILLIS: u64 = 1; +static DURATION_MILLIS: u64 = 5; #[derive(Deserialize, Debug)] struct ConfigVariables { subscriptions: Vec, } -#[pyo3_asyncio::tokio::main] +#[tokio::main] pub async fn main() -> PyResult<()> { // Subscribe let variables = envy::from_env::().unwrap(); @@ -81,6 +81,7 @@ pub async fn main() -> PyResult<()> { } let now = Instant::now(); + let outputs = call(&py_function, states.clone()).await.unwrap(); println!("call python {:#?}", now.elapsed()); @@ -90,7 +91,6 @@ pub async fn main() -> PyResult<()> { } states_hash = hash(&states); - println!("loop {:#?}", now.elapsed()); } }