<commit_before>require 'listen/adapter'
require 'listen/change'
require 'listen/record'

module Listen
  class Listener
    attr_accessor :options, :directories, :paused, :changes, :block

    RELATIVE_PATHS_WITH_MULTIPLE_DIRECTORIES_WARNING_MESSAGE = "The relative_paths option doesn't work when listening to multiple diretories."

    # Initializes the directories listener.
    #
    # @param [String] directory the directories to listen to
    # @param [Hash] options the listen options (see Listen::Listener::Options)
    #
    # @yield [modified, added, removed] the changed files
    # @yieldparam [Array<String>] modified the list of modified files
    # @yieldparam [Array<String>] added the list of added files
    # @yieldparam [Array<String>] removed the list of removed files
    #
    def initialize(*args, &block)
      @options     = _init_options(args.last.is_a?(Hash) ? args.pop : {})
      @directories = args.flatten.map { |path| Pathname.new(path) }
      @changes     = []
      @block       = block
    end

    # Starts the listener by initializing the adapter and building
    # the directory record concurrently, then it starts the adapter to watch
    # for changes. The current thread is not blocked after starting.
    #
    def start
      _signals_trap
      _init_actors
      unpause
      adapter.async.start
      Thread.new { _wait_for_changes }
    end

    def stop
      Celluloid::Actor.kill(adapter)
      Celluloid::Actor[:listen_change_pool].terminate
      record && record.terminate
    end

    def pause
      @paused = true
    end

    def unpause
      _build_record_if_needed
      @paused = false
    end

    def paused?
      @paused == true
    end

    def listen?
      @paused == false<commit_msg>Kill Listener thread on stop<commit_after>require 'listen/adapter'
require 'listen/change'
require 'listen/record'

module Listen
  class Listener
    attr_accessor :options, :directories, :paused, :changes, :block

    RELATIVE_PATHS_WITH_MULTIPLE_DIRECTORIES_WARNING_MESSAGE = "The relative_paths option doesn't work when listening to multiple diretories."

    # Initializes the directories listener.
    #
    # @param [String] directory the directories to listen to
    # @param [Hash] options the listen options (see Listen::Listener::Options)
    #
    # @yield [modified, added, removed] the changed files
    # @yieldparam [Array<String>] modified the list of modified files
    # @yieldparam [Array<String>] added the list of added files
    # @yieldparam [Array<String>] removed the list of removed files
    #
    def initialize(*args, &block)
      @options     = _init_options(args.last.is_a?(Hash) ? args.pop : {})
      @directories = args.flatten.map { |path| Pathname.new(path) }
      @changes     = []
      @block       = block
    end

    # Starts the listener by initializing the adapter and building
    # the directory record concurrently, then it starts the adapter to watch
    # for changes. The current thread is not blocked after starting.
    #
    def start
      _signals_trap
      _init_actors
      unpause
      adapter.async.start
      @thread = Thread.new { _wait_for_changes }
    end

    def stop
      Celluloid::Actor.kill(adapter)
      Celluloid::Actor[:listen_change_pool].terminate
      record && record.terminate
      @thread && @thread.kill
    end

    def pause
      @paused = true
    end

    def unpause
      _build_record_if_needed
      @paused = false
    end

    def paused?
      @paused == true
    end

    def listen?
      @paused == false
{'fraction_non_alphanumeric': 0.08218793828892006, 'fraction_numerical': 0.0, 'mean_word_length': 2.880304678998912, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '3477241', 'n_tokens_mistral': 1069, 'n_tokens_neox': 1013, 'n_words': 322}