Module: MachineLearningWorkbench::Tools::Execution

Defined in:
lib/machine_learning_workbench/tools/execution.rb

Class Method Summary collapse

Class Method Details

.in_fork(&block) ⇒ Object

Note:

add ‘ensure MachineLearningWorkbench::Tools.kill_forks` to the block where `in_fork` is called (see `#kill_forks`).

Executes block in a (detached) fork, saving the ‘pid` for later termination.



10
11
12
13
14
15
# File 'lib/machine_learning_workbench/tools/execution.rb', line 10

def self.in_fork &block
  raise ArgumentError "Need block to be executed in fork" unless block
  pid = fork(&block)
  Process.detach pid
  $fork_pids << pid
end

.kill_forksObject

Kills processes spawned by ‘#in_fork`. Call this in an `ensure` block after using `in_fork`.

> ‘ensure MachineLearningWorkbench::Tools.kill_forks`



20
21
22
23
# File 'lib/machine_learning_workbench/tools/execution.rb', line 20

def self.kill_forks
  $fork_pids&.each { |pid| Process.kill('KILL', pid) rescue Errno::ESRCH }
  $fork_pids = []
end