When to use Python::gil and passing py in the method or function? #4427
-
Hello, I have a question about the #[pyfunction]
fn test(values: Vec<f32>, delay_value: usize) -> PyResult<()> {
let training_file_path = Path::new("src\\assets\\white_500_2000.wav");
let noise_data = read_wave_file(training_file_path).unwrap();
test_actual(noise_data, values, delay);
Ok(())
} and then I add it to the module like this: #[pymodule]
fn python_rust_cancellation(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(test, m)?)?;
Ok(())
} So I am wondering if it is required to pass in the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It is not required to have |
Beta Was this translation helpful? Give feedback.
It is not required to have
py: Python
as a function argument if you don't need it. The GIL will still be held and to release it you'll need to callpy.allow_threads()
(thereby requiring apy
token!)