diff options
Diffstat (limited to 'lib/nlp_ruby/misc.rb')
-rw-r--r-- | lib/nlp_ruby/misc.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/nlp_ruby/misc.rb b/lib/nlp_ruby/misc.rb index 9a4064f..1fa3878 100644 --- a/lib/nlp_ruby/misc.rb +++ b/lib/nlp_ruby/misc.rb @@ -2,5 +2,31 @@ class Array def max_index self.index(self.max) end + + def is_subset_of? other + self.each { |i| + if other.include? i + return false + end + } + return true + end +end + +def spawn_with_timeout cmd, t=4, debug=false + require 'timeout' + 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 + return "" + # accept the zombies + #Process.kill('TERM', pid) + end + pipe_out.close + return pipe_in.read end + |