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

Is there a way to abort long-running load/decode operations? #78

Closed
cmbruns opened this issue Jun 23, 2024 · 1 comment
Closed

Is there a way to abort long-running load/decode operations? #78

cmbruns opened this issue Jun 23, 2024 · 1 comment

Comments

@cmbruns
Copy link

cmbruns commented Jun 23, 2024

Something like

  for status in incremental_decoder(in_file_stream, chunk_size):
     if user_pressed_cancel():
      break
    if status == COMPLETE:
     bgr_array = status.result
     break

...preferably with a larger default chunk size than the libjpeg-turbo C jpeg_read_scanlines(...) call.

@lilohuang
Copy link
Owner

TL;DR: PyTurboJPEG is a wrapper for the TurboJPEG C-API of the libjpeg-turbo library, which does not support the jpeg_read_scanlines function call or a similar function to abort long-running load/decode operations.

A viable workaround is using Python's multiprocessing library or a similar approach to launch a worker process, and call the terminate() function if it exceeds a timeout value. https://docs.python.org/3/library/multiprocessing.html#multiprocessing.Process.terminate

The libjpeg-turbo library provides two C-APIs: the TurboJPEG C-API and the libjpeg C-API. The jpeg_read_scanlines function is only available in the conventional libjpeg C-API. Even the official TurboJPEG Java API doesn't provide this functionality. See details at libjpeg-turbo Documentation.

Since this is outside the scope of using the TurboJPEG C-API, I’m going to close this issue. Thank you for your understanding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants