<commit_before>module Vizsla
  class Recorder
    THREAD_LOCAL_KEY = :_vizsla_current
    LOCK = Mutex.new

    class << self
      def current
        Thread.current[THREAD_LOCAL_KEY]
      end

      def current=(val)
        Thread.current[THREAD_LOCAL_KEY] = val
      end

      def start_recording
        self.current = []
      end

      def recording?
        !self.current.nil?
      end

      def add_event(event)
        return unless self.recording?
        self.current << event
      end

      def events
        self.current
      end

      def stop_recording
        Thread.current[THREAD_LOCAL_KEY] = nil
      end
    end
  end
end<commit_msg>ad threadsafety stuff to recorder<commit_after>module Vizsla
  class Recorder
    THREAD_LOCAL_KEY = :_vizsla_current
    LOCK = Mutex.new

    class << self
      def current
        LOCK.synchronize do
          Thread.current[THREAD_LOCAL_KEY]
        end
      end

      def current=(val)
        Thread.current[THREAD_LOCAL_KEY] = val
      end

      def start_recording
        self.current = []
      end

      def recording?
        !self.current.nil?
      end

      def add_event(event)
        return unless self.recording?
        self.current << event
      end

      def events
        self.current
      end

      def stop_recording
        LOCK.synchronize do
          Thread.current[THREAD_LOCAL_KEY] = nil
        end
      end

      at_exit do
        self.stop_recording
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.05563002680965148, 'fraction_numerical': 0.0, 'mean_word_length': 1.6998191681735986, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, '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': '4855325', 'n_tokens_mistral': 460, 'n_tokens_neox': 436, 'n_words': 107}