Actions
Bug #18375
closedTimeout.timeout(sec, klass: MyExceptionClass) can not retry correctly.
Bug #18375:
Timeout.timeout(sec, klass: MyExceptionClass) can not retry correctly.
Actions
Added by zw963 (Wei Zheng) almost 5 years ago. Updated almost 5 years ago.
I don't think this is a bug, and I don't think timeout can work with your proposed code. There's no way the block-level rescue can work the way you want, since what you want requires the timeout method be called again.
This code:
Timeout.timeout(2, DelayError) do |arg|
puts 'start'
sleep 10
rescue DelayError
puts '*'*10
retry
end
is short for:
Timeout.timeout(2, DelayError) do |arg|
begin
puts 'start'
sleep 10
rescue DelayError
puts '*'*10
retry
end
end
It's not short for:
begin
Timeout.timeout(2, DelayError) do |arg|
puts 'start'
sleep 10
end
rescue DelayError
puts '*'*10
retry
end
Even if it were short for that, that code doesn't work the way you want either (looks like an infinite loop). You probably want something like:
jeremyevans0 (Jeremy Evans) wrote in #note-2:
I don't think this is a bug, and I don't think timeout can work with your proposed code. There's no way the block-level
rescuecan work the way you want, since what you want requires thetimeoutmethod be called again.This code:
Timeout.timeout(2, DelayError) do |arg| puts 'start' sleep 10 rescue DelayError puts '*'*10 retry endis short for:
Timeout.timeout(2, DelayError) do |arg| begin puts 'start' sleep 10 rescue DelayError puts '*'*10 retry end endIt's not short for:
begin Timeout.timeout(2, DelayError) do |arg| puts 'start' sleep 10 end rescue DelayError puts '*'*10 retry endEven if it were short for that, that code doesn't work the way you want either (looks like an infinite loop). You probably want something like:
In fact, if consider following code more useful than the actually form.
begin
Timeout.timeout(2, DelayError) do |arg|
puts 'start'
sleep 10
end
rescue DelayError
puts '*'*10
retry
end
Perhaps, we should do some specially process for Timeout.timeout rescue block.