Browse Source

Removing asyncio

tags/v0.0.0-test.4
haixuanTao 4 years ago
parent
commit
1136264755
3 changed files with 14 additions and 19 deletions
  1. +4
    -2
      app.py
  2. +7
    -14
      src/python_binding.rs
  3. +3
    -3
      src/server.rs

+ 4
- 2
app.py View File

@@ -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"}

+ 7
- 14
src/python_binding.rs View File

@@ -29,20 +29,13 @@ pub async fn call(
py_function: &PyObject,
states: BTreeMap<String, String>,
) -> eyre::Result<HashMap<String, String>> {
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("")
}

+ 3
- 3
src/server.rs View File

@@ -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<String>,
}

#[pyo3_asyncio::tokio::main]
#[tokio::main]
pub async fn main() -> PyResult<()> {
// Subscribe
let variables = envy::from_env::<ConfigVariables>().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());
}
}


Loading…
Cancel
Save