lib/ztk/parallel.rb in ztk-1.18.5 vs lib/ztk/parallel.rb in ztk-1.19.0
- old
+ new
@@ -133,11 +133,12 @@
# @option config [Integer] :max_forks Maximum number of forks to use.
# @option config [Proc] :before_fork (nil) Proc to call before forking.
# @option config [Proc] :after_fork (nil) Proc to call after forking.
def initialize(configuration={})
super({
- :max_forks => MAX_FORKS
+ :max_forks => MAX_FORKS,
+ :raise_exceptions => true
}, configuration)
(config.max_forks < 1) and log_and_raise(ParallelError, "max_forks must be equal to or greater than one!")
@forks = Array.new
@@ -223,11 +224,11 @@
if !pid.nil? && !status.nil? && !(fork = @forks.select{ |f| f[:pid] == pid }.first).nil?
data = (Marshal.load(Base64.decode64(fork[:reader].read.to_s)) rescue nil)
config.ui.logger.debug { "read(#{data.inspect})" }
- process_exception_data(data)
+ data = process_data(data)
!data.nil? and @results.push(data)
fork[:reader].close
fork[:writer].close
@@ -282,16 +283,20 @@
end
private
- def process_exception_data(data)
- return if !(ZTK::Parallel::ExceptionWrapper === data)
+ def process_data(data)
+ return data if !(ZTK::Parallel::ExceptionWrapper === data)
config.ui.logger.fatal { "exception(#{data.exception.inspect})" }
- signal_all
- raise data.exception
+ if (config.raise_exceptions == true)
+ signal_all
+ raise data.exception
+ end
+
+ return data.exception
end
end
end