Method: #spawn_with_timeout
- Defined in:
- lib/zipf/misc.rb
#spawn_with_timeout(cmd, t = 4, ignore_fail = false, debug = false) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/zipf/misc.rb', line 60 def spawn_with_timeout cmd, t=4, ignore_fail=false, debug=false STDERR.write cmd+"\n" if debug pipe_in, pipe_out = IO.pipe pid = Process.spawn(cmd, :out => pipe_out) begin Timeout.timeout(t) { Process.wait pid } rescue Timeout::Error Process.kill('TERM', pid) if !ignore_fail end pipe_out.close return pipe_in.read end |