Max Max - 3 months ago 10
Ruby Question

Ruby Thread Pool abort_on_exception

I'm using Ruby's

Thread.pool
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
    abort_on_exception
    is supposed to be an attribute in
    Thread.pool
    . I'm using threads version 0.2.2.


Answer

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.

Comments