Sha256: b9fa24155fd4393db9a8bf31edd7661b1142b32d6e1bf3d24f1134e3038c0124
Contents?: true
Size: 886 Bytes
Versions: 5
Compression:
Stored size: 886 Bytes
Contents
require 'timeout' module Percy class ProcessHelpers DEFAULT_TERM_GRACE_SECONDS = 10 def self.gracefully_kill(pid, grace_period_seconds: DEFAULT_TERM_GRACE_SECONDS) begin Process.kill('TERM', pid) Timeout.timeout(grace_period_seconds) do Process.wait(pid) end rescue Errno::ESRCH # No such process. return false rescue Errno::ECHILD # Status has already been collected, perhaps by a Process.detach thread. return false rescue Timeout::Error begin Process.kill('KILL', pid) rescue Errno::ESRCH # If the process has already ended, suppress any additional errors return false end # Collect status so it doesn't stick around as zombie process. Process.wait(pid, Process::WNOHANG) end true end end end
Version data entries
5 entries across 5 versions & 1 rubygems