module MachineLearningWorkbench::Tools::Forkable
Public Class Methods
in_fork(&block)
click to toggle source
Executes block in a (detached) fork, saving the `pid` for later termination. @note add `ensure MachineLearningWorkbench::Tools.kill_forks` to the block
where `in_fork` is called (see `#kill_forks`).
# 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_forks()
click to toggle source
Kills processes spawned by `#in_fork`. Call this in an `ensure` block after using `in_fork`.
> `ensure MachineLearningWorkbench::Tools.kill_forks`¶ ↑
# 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