<commit_before>require 'logger'
require 'thread'
require 'timeout'
require 'set'
require 'facter'

module Celluloid
  extend self # expose all instance methods as singleton methods

  # How long actors have to terminate
  SHUTDOWN_TIMEOUT = 120

  # Warning message added to Celluloid objects accessed outside their actors
  BARE_OBJECT_WARNING_MESSAGE = "WARNING: BARE CELLULOID OBJECT "

  class << self
    attr_accessor :logger     # Thread-safe logger class
    attr_accessor :task_class # Default task type to use

    def included(klass)
      klass.send :extend,  ClassMethods
      klass.send :include, InstanceMethods
    end

    # Are we currently inside of an actor?
    def actor?
      !!Thread.current[:actor]
    end

    # Generate a Universally Unique Identifier
    def uuid
      UUID.generate
    end

    # Obtain the number of CPUs in the system
    def cores
      core_count = Facter.fact(:processorcount).value
      Integer(core_count)
    end
    alias_method :cpus, :cores
    alias_method :ncpus, :cores

    # Perform a stack dump of all actors to the given output object
    def stack_dump(output = STDERR)
      Celluloid::StackDumper.dump(output)
    end
    alias_method :dump, :stack_dump

    # Define an exception handler for actor crashes
    def exception_handler(&block)
      Logger.exception_handler(&block)
    end

    # Shut down all running actors
    def shutdown
      Timeout.timeout(SHUTDOWN_TIMEOUT) do
        actors = Actor.all
        Logger.info "Terminating #{actors.size} actors..." if actors.size > 0

        # Attempt to shut down the supervision tree, if available
        Supervisor.root.terminate if Supervisor.root

        # Actors cannot self-terminate, you must do it for them
        Actor.all.each do |actor|
          begin
            actor.terminate!
          rescue DeadActorError, MailboxError
          end
        end

        Actor.all.each do |actor|
          begin
            Actor.join(actor)
          rescue DeadActorError, MailboxError
          end
        end

        Logger.info "Shutdown completed cleanly"
      end
    end
  end<commit_msg>Use debug loglevel for termination messages<commit_after>require 'logger'
require 'thread'
require 'timeout'
require 'set'
require 'facter'

module Celluloid
  extend self # expose all instance methods as singleton methods

  # How long actors have to terminate
  SHUTDOWN_TIMEOUT = 120

  # Warning message added to Celluloid objects accessed outside their actors
  BARE_OBJECT_WARNING_MESSAGE = "WARNING: BARE CELLULOID OBJECT "

  class << self
    attr_accessor :logger     # Thread-safe logger class
    attr_accessor :task_class # Default task type to use

    def included(klass)
      klass.send :extend,  ClassMethods
      klass.send :include, InstanceMethods
    end

    # Are we currently inside of an actor?
    def actor?
      !!Thread.current[:actor]
    end

    # Generate a Universally Unique Identifier
    def uuid
      UUID.generate
    end

    # Obtain the number of CPUs in the system
    def cores
      core_count = Facter.fact(:processorcount).value
      Integer(core_count)
    end
    alias_method :cpus, :cores
    alias_method :ncpus, :cores

    # Perform a stack dump of all actors to the given output object
    def stack_dump(output = STDERR)
      Celluloid::StackDumper.dump(output)
    end
    alias_method :dump, :stack_dump

    # Define an exception handler for actor crashes
    def exception_handler(&block)
      Logger.exception_handler(&block)
    end

    # Shut down all running actors
    def shutdown
      Timeout.timeout(SHUTDOWN_TIMEOUT) do
        actors = Actor.all
        Logger.debug "Terminating #{actors.size} actors..." if actors.size > 0

        # Attempt to shut down the supervision tree, if available
        Supervisor.root.terminate if Supervisor.root

        # Actors cannot self-terminate, you must do it for them
        Actor.all.each do |actor|
          begin
            actor.terminate!
          rescue DeadActorError, MailboxError
          end
        end

        Actor.all.each do |actor|
          begin
            Actor.join(actor)
          rescue DeadActorError, MailboxError
          end
        end

        Logger.debug "Shutdown completed cleanly"
      end
    end
  end
{'fraction_non_alphanumeric': 0.058577405857740586, 'fraction_numerical': 0.0018596001859600185, 'mean_word_length': 2.5097879282218596, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5475849', 'n_tokens_mistral': 1230, 'n_tokens_neox': 1174, 'n_words': 414}