Skip to content
Advertisement

How to call Python async function from Rust?

I have read this answer(How to call Rust async method from Python?) and what I want to do is the opposite of this.

I want to call a Python async function and await it in tokio’s runtime. Is it possible?

I have given it some tries but I am facing an error in the output.

This is how my python file looks like:

JavaScript

and this is how my lib.rs looks like:

JavaScript

I am getting the following error:

JavaScript

I clearly am passing an async function and converting it to a future. I am unable to figure out where I am going wrong. I have read the documentation of pyo3-async multiple times but I am still unable to figure it out. I would really appreciate some help.

Thanks in advance.

Advertisement

Answer

As suggested by @sebpuetz ,

All I needed was to change

JavaScript

to

JavaScript

as h on its own is just a function. h() is a coroutine, which was the required item.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement