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

Handling timeouts #93

Open
krystof-k opened this issue Feb 1, 2024 · 1 comment
Open

Handling timeouts #93

krystof-k opened this issue Feb 1, 2024 · 1 comment

Comments

@krystof-k
Copy link

krystof-k commented Feb 1, 2024

Hey there, I need to implement timeout for a long running Tesseract command.

I came up with two options how to do it:

  1. Add the timeout option to the RTesseract.new and reimplement the Command#run using the Open3.popen3 instead of Open3.capture3 and catch the timout there (if set)
  2. Add some async option to the RTesseract.new and implement some run_async and results methods, also using Open3.popen3, which would return PID therefore the timeout (killing the process) can be handled in the client code.

What do you think? Should I try to open a PR? Thanks!

@krystof-k
Copy link
Author

Just posting a workaround until this moves on, if anyone finds it useful.

Simply create a shell script wrapper around tesseract command:

#!/usr/bin/env sh

timeout 10s tesseract "$@"

And then use it when calling RTesseract:

RTesseract.new("image.jpeg", command: "./tesseract_with_timeout.sh").to_s

Unfortunately you cannot tell whether it timed out or it crashed:

begin
  RTesseract.new("image.jpeg", command: "./tesseract_with_timeout.sh").to_s
rescue RTesseract::Error => e
  raise e unless e.message.include?("Terminated")
  raise "Tesseract probably timed out"
end

So it would be still much better to handle it directly in the gem as proposed above.

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

1 participant