<commit_before>module Guard
  class Linux < Listener
    attr_reader :inotify, :files, :latency, :callback

    def initialize
      @inotify = INotify::Notifier.new
      @files   = []
      @latency = 0.5
    end

    def on_change(&callback)
      @callback = callback
      inotify.watch(Dir.pwd, :recursive, :modify, :create, :delete, :move) do |event|
        unless event.name == "" # Event on root directory
          @files << event.absolute_name
        end
      end
    rescue Interrupt
    end

    def start
      @stop = false
      watch_change
    end

    def stop
      @stop = true
      inotify.stop
    end

    def self.usable?
      require 'rb-inotify'
      if !defined?(INotify::VERSION) || Gem::Version.new(INotify::VERSION.join('.')) < Gem::Version.new('0.5.1')
        UI.info "Please update rb-inotify (>= 0.5.1)"
        false
      else
        true
      end
    rescue LoadError
      UI.info "Please install rb-inotify gem for Linux inotify support"
      false
    end

  private

    def watch_change
      while !@stop
        if Config::CONFIG['build'] =~ /java/ || IO.select([inotify.to_io], [], [], latency)
          inotify.process

          unless files.empty?
            files.map! { |file| file.gsub("#{Dir.pwd}/", '') }
            callback.call(files)
            files.clear
          end
          sleep latency
        end
      end
    end

  end
end<commit_msg>stop linux listener quickly<commit_after>module Guard
  class Linux < Listener
    attr_reader :inotify, :files, :latency, :callback

    def initialize
      @inotify = INotify::Notifier.new
      @files   = []
      @latency = 0.5
    end

    def on_change(&callback)
      @callback = callback
      inotify.watch(Dir.pwd, :recursive, :modify, :create, :delete, :move) do |event|
        unless event.name == "" # Event on root directory
          @files << event.absolute_name
        end
      end
    rescue Interrupt
    end

    def start
      @stop = false
      watch_change
    end

    def stop
      @stop = true
      inotify.stop
    end

    def self.usable?
      require 'rb-inotify'
      if !defined?(INotify::VERSION) || Gem::Version.new(INotify::VERSION.join('.')) < Gem::Version.new('0.5.1')
        UI.info "Please update rb-inotify (>= 0.5.1)"
        false
      else
        true
      end
    rescue LoadError
      UI.info "Please install rb-inotify gem for Linux inotify support"
      false
    end

  private

    def watch_change
      while !@stop
        if Config::CONFIG['build'] =~ /java/ || IO.select([inotify.to_io], [], [], latency)
          inotify.process

          unless files.empty?
            files.map! { |file| file.gsub("#{Dir.pwd}/", '') }
            callback.call(files)
            files.clear
          end
          sleep latency unless @stop
        end
      end
    end

  end
end
{'fraction_non_alphanumeric': 0.11359664452988466, 'fraction_numerical': 0.005592450192240475, 'mean_word_length': 1.8909090909090909, 'pattern_counts': {'":': 0, '<': 11, '<?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': '5602186', 'n_tokens_mistral': 916, 'n_tokens_neox': 890, 'n_words': 226}