<commit_before>require 'eventmachine'

module Combi
  class Reactor
    def self.start(&block)
      EM::error_handler do |error|
        STDERR << "ERROR IN EM\n"
        STDERR << "\t#{error.inspect}"
        STDERR << "\t#{error.backtrace.join("\t\n")}" << "\n"
      end
      log "-EM.start- the reactor is running: #{EM::reactor_running?}"
      raise "EM did not shut down" if EM::reactor_running?
      @@reactor_thread = Thread.new do
        log "------- starting EM reactor"
        EM::run do
          log "------- reactor started"
          Signal.trap("INT")  { EM::stop_event_loop }
          Signal.trap("TERM") { EM::stop_event_loop }
          block.call unless block.nil?
        end
        log "------- reactor stopped"
      end
      30.times do
        sleep 0.1 unless EM::reactor_running?
      end
    end

    def self.stop
      log "-EM.stop- the reactor is running: #{EM::reactor_running?}"
      EM::stop_event_loop if EM::reactor_running?
      50.times do
        sleep 0.3 if EM::reactor_running?
      end
    end<commit_msg>Remove signal handlers. Let the OS kill EM<commit_after>require 'eventmachine'

module Combi
  class Reactor
    def self.start(&block)
      EM::error_handler do |error|
        STDERR << "ERROR IN EM\n"
        STDERR << "\t#{error.inspect}"
        STDERR << "\t#{error.backtrace.join("\t\n")}" << "\n"
      end
      log "-EM.start- the reactor is running: #{EM::reactor_running?}"
      raise "EM did not shut down" if EM::reactor_running?
      @@reactor_thread = Thread.new do
        log "------- starting EM reactor"
        EM::run do
          log "------- reactor started"
          block.call unless block.nil?
        end
        log "------- reactor stopped"
      end
      30.times do
        sleep 0.1 unless EM::reactor_running?
      end
    end

    def self.stop
      log "-EM.stop- the reactor is running: #{EM::reactor_running?}"
      EM::stop_event_loop if EM::reactor_running?
      50.times do
        sleep 0.3 if EM::reactor_running?
      end
    end
{'fraction_non_alphanumeric': 0.1354523227383863, 'fraction_numerical': 0.007823960880195598, 'mean_word_length': 2.0088235294117647, 'pattern_counts': {'":': 0, '<': 19, '<?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': '1029761', 'n_tokens_mistral': 660, 'n_tokens_neox': 632, 'n_words': 178}