Module: MachineLearningWorkbench::Tools::Execution
- Defined in:
- lib/machine_learning_workbench/tools/execution.rb
Class Method Summary collapse
-
.in_fork(&block) ⇒ Object
Executes block in a (detached) fork, saving the ‘pid` for later termination.
-
.kill_forks ⇒ Object
Kills processes spawned by ‘#in_fork`.
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.
8 9 10 11 12 13 |
# File 'lib/machine_learning_workbench/tools/execution.rb', line 8 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_forks ⇒ Object
Kills processes spawned by ‘#in_fork`. Call this in an `ensure` block after using `in_fork`.
> ‘ensure MachineLearningWorkbench::Tools.kill_forks`
18 19 20 21 |
# File 'lib/machine_learning_workbench/tools/execution.rb', line 18 def self.kill_forks $fork_pids&.each { |pid| Process.kill('KILL', pid) rescue Errno::ESRCH } $fork_pids = [] end |