lib/rbbt/util/misc/development.rb in rbbt-util-5.14.38 vs lib/rbbt/util/misc/development.rb in rbbt-util-5.14.39

- old
+ new

@@ -4,11 +4,13 @@ dir ||= File.join(Path.caller_lib_dir(caller.first), 'lib') $LOAD_PATH.unshift(dir) unless $LOAD_PATH.include? dir end def self.pre_fork - Persist::CONNECTIONS.values.each do |db| db.close if db.write? end + Persist::CONNECTIONS.values.each do |db| + db.close if db.write? + end ObjectSpace.each_object(Mutex) do |m| begin m.unlock rescue ThreadError end if m.locked? @@ -274,11 +276,12 @@ puts "Tick ellapsed: #{ellapsed.to_i} s. #{(ellapsed * 1000).to_i - ellapsed.to_i * 1000} ms" $_last_time_tick = Time.now end end - def self.bootstrap(elems, num = :current, file = nil, options = {}, &block) + def self.bootstrap(elems, num = :current, options = {}, &block) + IndiferentHash.setup options num = :current if num.nil? cpus = case num when :current 10 when String @@ -287,23 +290,28 @@ if num < 100 num else 32000 / num end + else + raise "Parameter 'num' not understood: #{Misc.fingerprint num}" end - options = Misc.add_defaults options, :cpus => cpus, :bar => "Bootstrap in #{ cpus } cpus: #{ Misc.fingerprint Annotated.purge(elems) }", :into => Set.new + options = Misc.add_defaults options, :respawn => true, :cpus => cpus, :into => Set.new + options = Misc.add_defaults options, :bar => "Bootstrap in #{ options[:cpus] } cpus: #{ Misc.fingerprint Annotated.purge(elems) }" + respawn = options[:respawn] and options[:cpus] and options[:cpus].to_i > 1 index = (0..elems.length-1).to_a.collect{|v| v.to_s } TSV.traverse index, options do |pos| elem = elems[pos.to_i] elems.annotate elem if elems.respond_to? :annotate begin yield elem rescue Interrupt Log.warn "Process #{Process.pid} was aborted" end + raise RbbtProcessQueue::RbbtProcessQueueWorker::Respawn if respawn == :always and cpus > 1 nil end end def self.memory_use(pid=nil)