Class: Parallel::UserInterruptHandler
- Inherits:
-
Object
- Object
- Parallel::UserInterruptHandler
- Defined in:
- lib/parallel.rb
Constant Summary collapse
- INTERRUPT_SIGNAL =
:SIGINT
Class Method Summary collapse
- .kill(thing) ⇒ Object
-
.kill_on_ctrl_c(pids, options) ⇒ Object
kill all these pids or threads if user presses Ctrl+c.
Class Method Details
.kill(thing) ⇒ Object
192 193 194 195 196 197 |
# File 'lib/parallel.rb', line 192 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) ⇒ Object
kill all these pids or threads if user presses Ctrl+c
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/parallel.rb', line 172 def kill_on_ctrl_c(pids, ) @to_be_killed ||= [] old_interrupt = nil signal = .fetch(:interrupt_signal, INTERRUPT_SIGNAL) if @to_be_killed.empty? old_interrupt = trap_interrupt(signal) do warn '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 |