Sha256: 364173a7b0862f515d94c02193708134b08cf6cbbb4cc19559bf18cc1e647cf5

Contents?: true

Size: 806 Bytes

Versions: 65

Compression:

Stored size: 806 Bytes

Contents

class KuberKit::Tools::ProcessCleaner
  include KuberKit::Import[
    "shell.system_commands",
    "shell.local_shell"
  ]

  def clean
    stop_threads
    stop_child_proceses
  end

  def stop_threads
    Thread.list.each do |t| 
      t.abort_on_exception   = false
      t.report_on_exception  = false
      Thread.kill(t) if t != Thread.current
    end
  end

  def stop_child_proceses
    find_all_child_processes.each do |pid|
      system_commands.kill_process(local_shell, pid)
    end
  end

  private

    def find_all_child_processes
      pids = system_commands.find_pids_by_name(local_shell, "KIT=#{Process.pid}")
      pids + get_child_pids(pids)
    end

    def get_child_pids(pids)
      pids
        .map{ |p| system_commands.get_child_pids(local_shell, p) }
        .flatten
    end
end

Version data entries

65 entries across 65 versions & 1 rubygems

Version Path
kuber_kit-1.1.2 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-1.2.1 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-1.2.0 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-1.1.1 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-1.0.1 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-1.0.0 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-0.9.9 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-0.9.8 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-0.9.7 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-0.9.6 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-0.9.5 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-0.9.4 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-0.9.3 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-0.9.2 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-0.9.1 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-0.9.0 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-0.8.8 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-0.8.7 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-0.8.6 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-0.8.5 lib/kuber_kit/tools/process_cleaner.rb