<commit_before>require 'jruby'
require 'timeout'

module SafeTimeout
  def self.timeout(sec, klass=nil)
    return yield(sec) if sec == nil or sec.zero?
    thread = Thread.new { yield(sec) }

    if thread.join(sec).nil?
      java_thread = JRuby.reference(thread)
      thread.kill
      java_thread.native_thread.interrupt
      thread.join(0.15)
      raise (klass || Timeout::Error), 'execution expired'
    else
      thread.value
    end
  end
end<commit_msg>some timeout changes after chats to @headius, fingers crossed<commit_after>require 'jruby'
require 'timeout'

module SafeTimeout
  def self.timeout(sec, klass=nil)
    return yield(sec) if sec == nil or sec.zero?
    thread = Thread.new { yield(sec) }

    if thread.join(sec).nil?
      java_thread = JRuby.reference(thread)
      thread.raise
      thread.join(0.15)
      raise (klass || Timeout::Error), 'execution expired'
    else
      thread.value
    end
  end
end
{'fraction_non_alphanumeric': 0.10649627263045794, 'fraction_numerical': 0.006389776357827476, 'mean_word_length': 3.0869565217391304, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5068418', 'n_tokens_mistral': 308, 'n_tokens_neox': 297, 'n_words': 78}