Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support write_image_jpeg with async #130

Open
edgarriba opened this issue Sep 10, 2024 · 0 comments
Open

Support write_image_jpeg with async #130

edgarriba opened this issue Sep 10, 2024 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@edgarriba
Copy link
Member

Add support for writing images with async that can be useful for i/o bound tasks in robotics and avoid people creating their threadpool.

requested by @haixuanTao for dora-rs

Current impl:

pub fn write_image_jpeg(file_path: &str, image: PyImage) -> PyResult<()> {
    let image = Image::from_pyimage(image)
        .map_err(|e| PyErr::new::<pyo3::exceptions::PyException, _>(format!("{}", e)))?;
    F::write_image_jpeg(file_path, &image)
        .map_err(|e| PyErr::new::<pyo3::exceptions::PyException, _>(format!("{}", e)))?;
    Ok(())
}

proposal with async

pub fn write_image_jpeg(file_path: &str, image: PyImage) -> PyResult<()> {
    let image = Image::from_pyimage(image)
        .map_err(|e| PyErr::new::<pyo3::exceptions::PyException, _>(format!("{}", e)))?;
    use std::thread;
    thread::spawn(move || {
      F::write_image_jpeg(file_path, &image)
          .map_err(|e| PyErr::new::<pyo3::exceptions::PyException, _>(format!("{}", e)))?;
    });

    Ok(())
}

Discussed to return a join Handle so that people can query state pending, failure or success

@edgarriba edgarriba added enhancement New feature or request help wanted Extra attention is needed labels Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant