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.3.9 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-1.3.8 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-1.3.7 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-1.1.8 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-1.3.6 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-1.1.7 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-1.3.5 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-1.3.4 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-1.1.6 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-1.3.3 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-1.3.2 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-1.1.5 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-1.3.1 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-1.3.0 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-1.1.4 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-1.2.7 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-1.2.6 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-1.2.5 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-1.2.4 lib/kuber_kit/tools/process_cleaner.rb
kuber_kit-1.2.2 lib/kuber_kit/tools/process_cleaner.rb