def kill
      if @threads.empty?
        @log.debug("Thread pool \"#{@title}\" terminated with no threads")
        return
      end
      @log.debug("Stopping \"#{@title}\" thread pool with #{@threads.count} threads: \
#{@threads.map { |t| "#{t.name}/#{t.status}" }.join(', ')}...")
      start = Time.new
      begin
        join(0.1)
      ensure
        @threads.each do |t|
          (t.thread_variable_get(:kids) || []).each(&:kill)
          t.kill
          sleep(0.001) while t.alive? # I believe it's a bug in Ruby, this line fixes it
          Thread.current.thread_variable_set(
            :kids,
            (Thread.current.thread_variable_get(:kids) || []) - [t]
          )
        end
        @log.debug("Thread pool \"#{@title}\" terminated all threads in #{Age.new(start)}, \
it was alive for #{Age.new(@start)}: #{@threads.map { |t| "#{t.name}/#{t.status}" }.join(', ')}")
        @threads.clear
      end
    end
def kill
      if @threads.empty?
        @log.debug("Thread pool \"
        return
      end
      @log.debug("Stopping \"

      start = Time.new
      begin
        join(0.1)
      ensure
        @threads.each do |t|
          (t.thread_variable_get(:kids) || []).each(&:kill)
          t.kill
          sleep(0.001) while t.alive? 
          Thread.current.thread_variable_set(
            :kids,
            (Thread.current.thread_variable_get(:kids) || []) - [t]
          )
        end
        @log.debug("Thread pool \"
it was alive for 
        @threads.clear
      end
    end
def kill if @threads . empty? @log . debug ( "Thread pool \"#{@title}\" terminated with no threads" ) return end @log . debug ( "Stopping \"#{@title}\" thread pool with #{@threads.count} threads: \
#{@threads.map { |t| "#{t.name}/#{t.status}" }.join(', ')}..." ) start = Time . new begin join ( 0.1 ) ensure @threads . each do | t | ( t . thread_variable_get ( :kids ) || [ ] ) . each ( :kill ) t . kill sleep ( 0.001 ) while t . alive? # I believe it's a bug in Ruby, this line fixes it Thread . current . thread_variable_set ( :kids , ( Thread . current . thread_variable_get ( :kids ) || [ ] ) - [ t ] ) end @log . debug ( "Thread pool \"#{@title}\" terminated all threads in #{Age.new(start)}, \
it was alive for #{Age.new(@start)}: #{@threads.map { |t| "#{t.name}/#{t.status}" }.join(', ')}" ) @threads . clear end end
Kill them all immediately and close the pool
Kill them all immediately and close the pool