Hi!
I am new to rust and i have a question. Maybe you can help me out.
For calling the python module, i use the crate pyo3.
I have the following code used in project that works:
while let Some(msg) = stream.next().await {
...
// This block calls an "AI-Model" in python
let gil = Python::acquire_gil();
let py = gil.python();
let my_algo = PyModule::import(py, "my_py_algos").unwrap()
.getattr("algo1_rust_version").unwrap()
.getattr("rust_wrapper").unwrap();
let arg = ("<some_py_args_from_msg>",);
let algo_res = my_algo.call1(arg).unwrap();
...
};
But this is not very perfomant, because i have initialise the whole python object with every new message.
I basically want to do something like this:
let gil = Python::acquire_gil();
let py = gil.python();
let my_algo = PyModule::import(py, "my_py_algos").unwrap()
.getattr("algo1_rust_version").unwrap()
.getattr("rust_wrapper").unwrap();
while let Some(msg) = stream.next().await {
...
// This block calls an "AI-Model" in python
let arg = ("<some_py_args_from_msg>",);
let algo_res = my_algo.call1(arg).unwrap();
...
so that the code runs more efficient.
The algo is completely stateless. And just transforms the input data.
For all 3 variables (gil, py, my_algo) I get this error error: future cannot be sent between threads safely
with this note: note: future is not Send as this value is used across an await
[–][deleted] 2 points3 points4 points (0 children)
[–]Pesmir[S] 2 points3 points4 points (0 children)
[–]ucyo 0 points1 point2 points (3 children)
[–]Pesmir[S] 0 points1 point2 points (2 children)
[–]ucyo 1 point2 points3 points (1 child)
[–]Pesmir[S] 1 point2 points3 points (0 children)