<commit_before>require "thread"

module Celluloid
  class Group
    class Spawner < Group
      attr_accessor :finalizer

      def initialize
        super
      end

      def get(&block)
        assert_active
        fail ArgumentError.new("No block sent to Spawner.get()") unless block_given?
        instantiate block
      end

      def shutdown
        @running = false
        queue = []
        @mutex.synchronize do
          loop do
            break if @group.empty?
            th = @group.shift
            th.kill
            queue << th
          end
        end
        loop do
          break if queue.empty?
          queue.pop.join
        end
      end

      def idle?
        to_a.select { |t| t[:celluloid_meta] && t[:celluloid_meta][:state] == :running }.empty?
      end

      def busy?
        to_a.select { |t| t[:celluloid_meta] && t[:celluloid_meta][:state] == :running }.any?
      end

      private

      def instantiate(proc)
        thread = Thread.new do
          Thread.current[:celluloid_meta] = {
            started: Time.now,
            state: :running,
          }

          begin
            proc.call
          rescue ::Exception => ex
            Internals::Logger.crash("thread crashed", ex)
            Thread.current[:celluloid_meta][:state] = :error
          ensure
            unless Thread.current[:celluloid_meta][:state] == :error
              Thread.current[:celluloid_meta][:state] = :finished
            end
            @mutex.synchronize { @group.delete Thread.current }
          end
        end

        @mutex.synchronize { @group << thread }
        thread
      end
    end
  end
end
<commit_msg>remove needless shutdown code in Group::Spawner<commit_after>require "thread"

module Celluloid
  class Group
    class Spawner < Group
      attr_accessor :finalizer

      def initialize
        super
      end

      def get(&block)
        assert_active
        fail ArgumentError.new("No block sent to Spawner.get()") unless block_given?
        instantiate block
      end

      def shutdown
        @running = false
        #de queue = []
        @mutex.synchronize do
          loop do
            break if @group.empty?
            th = @group.shift
            th.kill
            #de queue << th
          end
        end
        #de loop do
        #de   break if queue.empty?
        #de   queue.pop.join
        #de end
      end

      def idle?
        to_a.select { |t| t[:celluloid_thread_state] == :running }.empty?
      end

      def busy?
        to_a.select { |t| t[:celluloid_thread_state] == :running }.any?
      end

      private

      def instantiate(proc)
        thread = Thread.new do
          Thread.current[:celluloid_meta] = {
            started: Time.now,
            state: :running,
          }

          begin
            proc.call
          rescue ::Exception => ex
            Internals::Logger.crash("thread crashed", ex)
            Thread.current[:celluloid_thread_state] = :error
          ensure
            unless Thread.current[:celluloid_thread_state] == :error
              Thread.current[:celluloid_thread_state] = :finished
            end
            @mutex.synchronize { @group.delete Thread.current }
          end
        end

        @mutex.synchronize { @group << thread }
        thread
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.08751493428912784, 'fraction_numerical': 0.0, 'mean_word_length': 1.533282904689864, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2988887', 'n_tokens_mistral': 959, 'n_tokens_neox': 934, 'n_words': 239}