-
-
Save eregon/9022f5709fa054fc4e488d7de085b254 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ready = false | |
thread = Thread.new do | |
loop do | |
$ready = true | |
begin | |
Thread.pass | |
rescue => e | |
p e | |
ensure | |
Thread.handle_interrupt(Object => :never) do # backtrace reports it happens here | |
begin | |
Thread.pass | |
rescue => e | |
abort "ensure saw #{e}" | |
end | |
end | |
end | |
end | |
end | |
1000.times { | |
Thread.pass until $ready | |
thread.raise "timeout" | |
Thread.pass | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ruby -v interrupt.rb |& cat | |
ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-linux] | |
#<RuntimeError: timeout> | |
#<Thread:0x00000000025c32b0 interrupt.rb:2 run> terminated with exception (report_on_exception is true): | |
interrupt.rb:10:in `handle_interrupt': timeout (RuntimeError) | |
from interrupt.rb:10:in `ensure in block (2 levels) in <main>' | |
from interrupt.rb:10:in `block (2 levels) in <main>' | |
from interrupt.rb:3:in `loop' | |
from interrupt.rb:3:in `block in <main>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment