Is there a way in Ruby to have it print the __LINE__ number of code (at my script level, not required gems) it’s working on if taking longer than 9 seconds (adjustable)?
For debugging I am getting it to print verbose output of what it’s trying to do, where it is in the code etc., rather than silently sitting for long periods of time.
A flaky situation makes it unpredicable how far it gets before something times out, so successive advancing doesn’t apply here.
EDIT
Something like a trap would work, such that:
- The original line number and hopefully code get remembered (both benchmark and timeout gems lose track of
__LINE__for instance…. Maybe there is a way to push it off to another .rb file to manipulate the stack to include my file & line of interest?) - When the overtime warning prints, execution still continues as if nothing had changed.
This will stop execution if the timeout block runs out of time and raise a Timeout error.
If you want to continue execution, you might do better with benchmark:
One benchmark block can have multiple timers:
See more about benchmark here:
http://ruby-doc.org/stdlib-1.9.3/libdoc/benchmark/rdoc/Benchmark.html
If you want to keep track of the line number being executed, why don’t you try passing it in to a custom method like so: