You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Has any thought been given to a timeout feature? The thinking here is that if the spawned command is spinning we'll want to abort it after a period of time. This leads to increased issue resiliency in the gem user's code.
Posix::Spawn has implemented their own approach to timeout in the gem which (I expect) avoids the safety issues in MRI Ruby's timeout. I did not see how the timeout parameter is passed through to Posix::Spawn in Terrapin. Additionally the other mechanisms for running the command do not appear to have any timeout handling code. Jruby would be addressed as well.
Would this be a welcome addition to the gem?
The text was updated successfully, but these errors were encountered:
jayjlawrence
changed the title
addition of tiimeout feature?
Addition of timeout feature?
Jul 31, 2018
By the way I have on my code the call method on ProcessRunner overriden to get that timeout behaviour on my scripts. Not my best code but is working so far.
require 'timeout'
module Terrapin
class TimeoutError < CommandLineError; end
class CommandLine
class ProcessRunner
def call(command, env = {}, options = {})
pipe = MultiPipe.new
#puts 'starting process'
timeout = options.delete(:timeout)
pid = spawn(env, command, options.merge(pipe.pipe_options))
begin
#A value of 0 or nil will execute the block without any timeout.
Timeout.timeout(timeout) do
#puts 'waiting for the process #{pid} to end'
pipe.read_and_then do
waitpid(pid)
end
#puts 'process #{pid} finished in time'
end
pipe.output
rescue Timeout::Error
#puts 'Process #{pid} not finished in time, killing it'
#https://blog.simplificator.com/2016/01/18/how-to-kill-processes-on-windows-using-ruby/
Terrapin::OS.windows? ? system("taskkill /f /pid #{pid}") : Process.kill('TERM', pid)
raise Terrapin::TimeoutError, "Process #{pid} killed, not finished in time"
end
end
end
end
end
Has any thought been given to a timeout feature? The thinking here is that if the spawned command is spinning we'll want to abort it after a period of time. This leads to increased issue resiliency in the gem user's code.
Posix::Spawn has implemented their own approach to timeout in the gem which (I expect) avoids the safety issues in MRI Ruby's timeout. I did not see how the timeout parameter is passed through to Posix::Spawn in Terrapin. Additionally the other mechanisms for running the command do not appear to have any timeout handling code. Jruby would be addressed as well.
Would this be a welcome addition to the gem?
The text was updated successfully, but these errors were encountered: