<commit_before>require 'spork/test_framework/qspec'

module Qspec
  module SporkHelper
    PORT = ::Spork::TestFramework::Qspec::DEFAULT_PORT

    def start_spork_workers
      @qspec_opts[:count].times do |i|
        spawn({ "TEST_ENV_NUMBER" => i == 0 ? '' : (i + 1).to_s },
              "spork qspec --port #{PORT+i}")
      end
      Signal.trap(:INT){
        output.puts "Stop spork processes"
        exit(0)
      }
      Process.waitall.all? { |pid, status| status.exitstatus == 0 } ? 0 : 1
    end
  end
end<commit_msg>Create file for port numbers<commit_after>require 'spork/test_framework/qspec'

module Qspec
  module SporkHelper
    PORT = ::Spork::TestFramework::Qspec::DEFAULT_PORT

    def start_spork_workers
      Signal.trap(:INT){
        output.puts "Stop spork processes"
        remove_port_file
        exit(0)
      }

      ports = []
      @qspec_opts[:count].times do |i|
        spawn({ "TEST_ENV_NUMBER" => i == 0 ? '' : (i + 1).to_s },
              "spork qspec --port #{PORT+i}")
        ports << PORT+i
      end
      create_port_file(ports)
      Process.waitall.all? { |pid, status| status.exitstatus == 0 } ? 0 : 1
    end

    def create_port_file(ports)
      File.open('tmp/qspec_spork', 'w') do |f|
        f.puts ports.join("\n")
      end
    end

    def runnning_ports
      @runnning_ports ||= begin
        ports = File.readlines('tmp/qspec_spork').map { |line| line.strip.to_i }
        ports.empty? ? nil : ports
      rescue Errno::ENOENT
        nil
      end
    end

    def remove_port_file
      File.unlink('tmp/qspec_spork')
    end
  end
end
{'fraction_non_alphanumeric': 0.1285892634207241, 'fraction_numerical': 0.00749063670411985, 'mean_word_length': 2.2983539094650207, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2455371', 'n_tokens_mistral': 564, 'n_tokens_neox': 550, 'n_words': 118}