我在循环中有这段ruby代码:
pid = Process.spawn("my_process_command")
begin
Timeout.timeout(16) do
`my_timeout_command`
Process.wait(pid)
end
rescue
system("clear")
puts 'Process not finished in time, killing it'
Process.kill('TERM', pid)
end
问题是,一旦捕获了Timeout :: Error异常,就会跳过该块,并且循环几乎不做任何事情。我该如何解决这个问题?
答案 0 :(得分:1)
rescue
以后,您需要Timeout:Error
专门针对pid = Process.spawn("my_process_command")
begin
Timeout.timeout(16) do
`my_timeout_command`
Process.wait(pid)
end
rescue Timeout::Error
system("clear")
puts 'Process not finished in time, killing it'
Process.kill('TERM', pid)
end
:
{{1}}