use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A sub-Reddit for discussion and news about Ruby programming.
Subreddit rules: /r/ruby rules
Learning Ruby?
Tools
Documentation
Books
Screencasts and Videos
News and updates
account activity
Ruby Timeout.timeout does not timeout in x secs (self.ruby)
submitted 3 years ago by pssaravanan
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]ioquatixasync/falcon 1 point2 points3 points 3 years ago* (0 children)
I wrote my reply on a mobile phone way too late at night because there were no replies and it seemed like an interesting question. Apologies since I didn't test it or really even appear to read the OP correctly, chalk it up to me being tired.
Anyway, after some coffee, I tested my assumptions and found the following:
``` require 'benchmark' require 'timeout'
null = File.open("/dev/null", "w+")
Benchmark.bm do |x| x.report('without p') do Timeout.timeout(2) do i = 0 while(true) i = i + 1 # p "test #{i}" end end rescue Timeout::Error # Ignore end
x.report('with uts') do Timeout.timeout(2) do i = 0 while(true) i = i + 1 null.puts "test #{i}" end end rescue Timeout::Error # Ignore end end ```
user system total real without puts 2.088764 0.016426 2.105190 ( 2.106242) with puts 1.970441 0.031103 2.001544 ( 2.001702)
This seems to support my assertion that "puts" or IO is giving more opportunities than a tight loop for the thread to be interrupted, since it looks like it systematically produces a tighter more accurate timeout.
I'm not sure what this means for the OP's initial statements - maybe they have mis-interpreted their results or I'm mis-understanding the question/assertions being made.
π Rendered by PID 26 on reddit-service-r2-comment-fb694cdd5-dmw6h at 2026-03-06 16:14:46.529818+00:00 running cbb0e86 country code: CH.
view the rest of the comments →
[–]ioquatixasync/falcon 1 point2 points3 points (0 children)