Module: SafeTimeout
- Defined in:
- lib/safe_timeout.rb,
lib/safe_timeout/version.rb,
lib/safe_timeout/interrupting_child_process.rb
Overview
Ruby’s Timeout is broken and highly dangerous. To avoid this risk we instead use a child process to handle the timeout. We fork it and let it issue a SIGINT (Ctrl-C) to the parent if the timeout is reached.
Defined Under Namespace
Classes: InterruptingChildProcess
Constant Summary collapse
- VERSION =
"0.0.1"
Class Method Summary collapse
Class Method Details
.timeout(sec, klass = nil, &block) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/safe_timeout.rb', line 8 def self.timeout(sec, klass=nil, &block) InterruptingChildProcess.new( :timeout => sec, :on_timeout => lambda { |_| raise(klass || Timeout::Error) } ).start(&block) end |