对于目录中的每个文件,我需要对其进行处理,然后将结果写入另一个文件。如果引发超时异常,则继续循环的下一次迭代。
 require 'timeout'
 timeout_in_seconds = 60
 for fl in Dir.glob('/dir/files')
     begin 
     Timeout::timeout(timeout_in_seconds) do 
 #do something here to get $results
 File.open('new_file', 'w') { |file| file.write(results) }
     end
     rescue Timeout::Error
 next
 end
从shell运行错误是:
  syntax error, 'unexpected kRESCUE, expecting kEND
rescue Timeout::Error
关于如何纠正这个问题的任何想法?