Max Max - 1 month ago 5x
Ruby Question

Ruby Thread Pool abort_on_exception

I'm using Ruby's

to manage ten threads for my program. I'm having two issues though:

  1. I want to enable abort_on_exception for the pool. My relevant code is:

    pool = Thread.pool(thread_count)
    pool.abort_on_exception = true

    However I'm getting

    undefined method abort_on_exception= for #<Thread::Pool:0x007fb25bb144b8> (NoMethodError)

    when I run it. I've triple-checked and
    is supposed to be an attribute in
    . I'm using threads version 0.2.2.


The abort_on_exception method is defined on the Thread::Pool class itself, not on the individual instances. As such, you have to call

Thread::Pool.abort_on_exception = true

This method thus works very similar to Thread.abort_on_exception in the Ruby language core.