Class: Parallel::UserInterruptHandler

### Home Classes Methods

### In Files

- lib/parallel.rb

### Parent

Object

### Methods

- ::kill
- ::kill_on_ctrl_c

### Class/Module Index

Quicksearch

- Parallel
- Parallel::Break
- Parallel::DeadWorker
- Parallel::ExceptionWrapper
- Parallel::JobFactory
- Parallel::Kill
- Parallel::ProcessorCount
- Parallel::UserInterruptHandler
- Parallel::Worker

No matching classes.

# Parallel::UserInterruptHandler

### Constants

INTERRUPT_SIGNAL

### Public Class Methods

kill(thing) click to toggle source

    # File lib/parallel.rb, line 149
    def kill(thing)
      Process.kill(:KILL, thing)
    rescue Errno::ESRCH
      # some linux systems already automatically killed the children at this point
      # so we just ignore them not being there
    end

kill_on_ctrl_c(pids, options) click to toggle source

kill all these pids or threads if user presses Ctrl+c

    # File lib/parallel.rb, line 129
    def kill_on_ctrl_c(pids, options)
      @to_be_killed ||= []
      old_interrupt = nil
      signal = options.fetch(:interrupt_signal, INTERRUPT_SIGNAL)

      if @to_be_killed.empty?
        old_interrupt = trap_interrupt(signal) do
          $stderr.puts 'Parallel execution interrupted, exiting ...'
          @to_be_killed.flatten.each { |pid| kill(pid) }
        end
      end

      @to_be_killed << pids

      yield
    ensure
      @to_be_killed.pop # do not kill pids that could be used for new processes
      restore_interrupt(old_interrupt, signal) if @to_be_killed.empty?
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.