Sha256: 81f80a1f1101ce6a2b234806075ddb21074ed129855519c078050af6aa785cf3

Contents?: true

Size: 730 Bytes

Versions: 19

Compression:

Stored size: 730 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
        Process.kill('KILL', pid)
        # Collect status so it doesn't stick around as zombie process.
        Process.wait(pid, Process::WNOHANG)
      end
      true
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
percy-common-3.1.4 lib/percy/process_helpers.rb
percy-common-3.1.3 lib/percy/process_helpers.rb
percy-common-3.1.2 lib/percy/process_helpers.rb
percy-common-3.1.2.pre.rc.3 lib/percy/process_helpers.rb
percy-common-3.1.2.pre.rc.2 lib/percy/process_helpers.rb
percy-common-3.1.2.rc.1 lib/percy/process_helpers.rb
percy-common-3.1.1 lib/percy/process_helpers.rb
percy-common-3.1.0 lib/percy/process_helpers.rb
percy-common-3.0.2 lib/percy/process_helpers.rb
percy-common-3.0.1 lib/percy/process_helpers.rb
percy-common-3.0.0 lib/percy/process_helpers.rb
percy-common-2.1.1 lib/percy/process_helpers.rb
percy-common-2.1.0 lib/percy/process_helpers.rb
percy-common-2.0.0 lib/percy/process_helpers.rb
percy-common-1.5.0 lib/percy/process_helpers.rb
percy-common-1.4.1 lib/percy/process_helpers.rb
percy-common-1.4.0 lib/percy/process_helpers.rb
percy-common-1.3.0 lib/percy/process_helpers.rb
percy-common-1.2.0 lib/percy/process_helpers.rb