Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在评估一些代码,有时会看到我正在执行的 Ruby 代码运行超过 60 秒。
有没有人有一个基于时间限制引发异常的例子?
require "timeout" Timeout.timeout(60) do <your code here> end
这将引发Timeout::Error异常。您还可以将自定义异常传递给超时:
Timeout::Error
Timeout.timeout(60, <CustomException>)
有关更多信息,请参阅超时文档。