Replies: 3 comments 12 replies
-
You can do something similar to what https://pyo3.rs/main/class/call.html does: store the function as a |
Beta Was this translation helpful? Give feedback.
-
Well, you can't do that. You can't turn a python function into a rust function. At best you can take a python function and wrap it in a rust function, but you will still need to acquire the GIL to call it. |
Beta Was this translation helpful? Give feedback.
-
I don't think this can be simplified significantly. There is no need to give the inner GIL token a different name though, it can just show the outer one which cannot "enter" the closure passed to Please not that as written in the example, the parallel iteration is completely useless as the closure passed to |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Okay so I understand so far that we can call rust functions from python and also other way around but how do I take a python function extract it into a rust function to be passed around in rust?
Allow me to elaborate!
I have a function in rust library that I'am building that takes a function which I would like to get from python.
Now I wish to write a python function module that takes python function (probably as PyObject?) and extract it into a rust function to be passed around like so:
But this returns error:
How do I do it in pyO3? Or if it is even possible?
I certainly am able to call python function passed as an argument in a directly like so:
From python:
Beta Was this translation helpful? Give feedback.
All reactions