Sha256: b1174d197eadf2a4ed2a3c724333a9c70d9e011fc9599a80b7e5de31abc556de

Contents?: true

Size: 786 Bytes

Versions: 14

Compression:

Stored size: 786 Bytes

Contents

# frozen_string_literal: true

module Polyphony
  # Process patches
  module Process
    class << self
      def watch(cmd = nil, &block)
        terminated = nil
        pid = cmd ? Kernel.spawn(cmd) : Polyphony.fork(&block)
        Thread.current.agent.waitpid(pid)
        terminated = true
      ensure
        kill_process(pid) unless terminated || pid.nil?
      end

      def kill_process(pid)
        cancel_after(5) do
          kill_and_await('TERM', pid)
        end
      rescue Polyphony::Cancel
        kill_and_await(-9, pid)
      end

      def kill_and_await(sig, pid)
        ::Process.kill(sig, pid)
        Thread.current.agent.waitpid(pid)
      rescue SystemCallError
        # ignore
        puts 'SystemCallError in kill_and_await'
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
polyphony-0.44.0 lib/polyphony/adapters/process.rb
polyphony-0.43.11 lib/polyphony/adapters/process.rb
polyphony-0.43.10 lib/polyphony/adapters/process.rb
polyphony-0.43.9 lib/polyphony/adapters/process.rb
polyphony-0.43.8 lib/polyphony/adapters/process.rb
polyphony-0.43.6 lib/polyphony/adapters/process.rb
polyphony-0.43.5 lib/polyphony/adapters/process.rb
polyphony-0.43.4 lib/polyphony/adapters/process.rb
polyphony-0.43.3 lib/polyphony/adapters/process.rb
polyphony-0.43.2 lib/polyphony/adapters/process.rb
polyphony-0.43.1 lib/polyphony/adapters/process.rb
polyphony-0.43 lib/polyphony/adapters/process.rb
polyphony-0.42 lib/polyphony/adapters/process.rb
polyphony-0.41 lib/polyphony/adapters/process.rb