<commit_before>require 'timeout'

module Splib

  @@processes = []
  @@owner ||= Thread.current
  Kernel.at_exit do
    if(Thread.current == @@owner)
      @@processes.each{|pro| Process.kill('KILL', pro.pid) }
    end
  end

  # Returns current array of running Processes
  def self.running_procs
    @@processes
  end
  # command:: command string to execute
  # timeout:: length of time to execute
  # maxbytes:: maximum number return bytes allowed
  # Execute system command. This is a wrapper method
  # that will redirect to the proper command
  def self.exec(*args)
    if(true) #RUBY_PLATFORM == 'java')
      thread_exec(*args)
    else
      standard_exec(*args)
    end
  end
  
  # command:: command to execute
  # timeout:: maximum number of seconds to run
  # maxbytes:: maximum number of result bytes to accept
  # priority:: set priority of the process
  # Execute a system command (use with care)
  # This is the normal exec command that is used
  def self.standard_exec(command, timeout=10, maxbytes=500, priority=nil)
    timeout = timeout.to_i
    maxbytes = maxbytes.to_i
    priority = priority.to_i
    output = []
    pro = nil
    begin
      if(timeout > 0)
        Timeout::timeout(timeout) do
          pro = IO.popen(command)
          @@processes << pro
          if(priority > 0)
            Process.setpriority(Process::PRIO_PROCESS, pro.pid, priority)
          end
          until(pro.closed? || pro.eof?)
            output << pro.getc.chr<commit_msg>Only use threaded exec on java (probably not required any more?)<commit_after>require 'timeout'

module Splib

  @@processes = []
  @@owner ||= Thread.current
  Kernel.at_exit do
    if(Thread.current == @@owner)
      @@processes.each{|pro| Process.kill('KILL', pro.pid) }
    end
  end

  # Returns current array of running Processes
  def self.running_procs
    @@processes
  end
  # command:: command string to execute
  # timeout:: length of time to execute
  # maxbytes:: maximum number return bytes allowed
  # Execute system command. This is a wrapper method
  # that will redirect to the proper command
  def self.exec(*args)
    if(RUBY_PLATFORM == 'java')
      thread_exec(*args)
    else
      standard_exec(*args)
    end
  end
  
  # command:: command to execute
  # timeout:: maximum number of seconds to run
  # maxbytes:: maximum number of result bytes to accept
  # priority:: set priority of the process
  # Execute a system command (use with care)
  # This is the normal exec command that is used
  def self.standard_exec(command, timeout=10, maxbytes=500, priority=nil)
    timeout = timeout.to_i
    maxbytes = maxbytes.to_i
    priority = priority.to_i
    output = []
    pro = nil
    begin
      if(timeout > 0)
        Timeout::timeout(timeout) do
          pro = IO.popen(command)
          @@processes << pro
          if(priority > 0)
            Process.setpriority(Process::PRIO_PROCESS, pro.pid, priority)
          end
          until(pro.closed? || pro.eof?)
            output << pro.getc.chr
{'fraction_non_alphanumeric': 0.09654943596549435, 'fraction_numerical': 0.0046449900464499, 'mean_word_length': 2.7876884422110555, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, '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': '2710202', 'n_tokens_mistral': 922, 'n_tokens_neox': 883, 'n_words': 292}