views:

32

answers:

0

When I run

Thread.abort_on_exception = true
threads = []

threads << Thread.new do
  loop { sleep 1 }
end

threads << Thread.new do
  loop { sleep 1; raise }
end

threads.each { |t| t.join }

as a straight-up ruby script, the script exits as you'd expect with abort_on_exception set to true.

But when I try to run this same code as a rake task

task :mytask do
  Thread.abort_on_exception = true
  threads = []

  threads << Thread.new do
    loop { sleep 1 }
  end

  threads << Thread.new do
    loop { sleep 1; raise }
  end

  threads.each { |t| t.join }
end

thread 2 aborts and pushes backtrace to the screen, but thread 1 keeps going!

Seems to be some conflict between rake and abort_on_exception. Any ideas on where to start?