lib/bundler/parallel_workers/unix_worker.rb
# Start forked workers for downloading gems. This version of worker
# is only used on platforms where fork is available.
#
# @param size [Integer] Size of worker pool
# @param func [Proc] Job that should be executed in the worker
Start forked workers for downloading gems. This version of worker
is only used on platforms where fork is available.
Start forked workers for downloading gems . This version of worker is only used on platforms where fork is available .
def prepare_workers(size, func)
        @workers = size.times.map do |num|
          child_read, parent_write = IO.pipe
          parent_read, child_write = IO.pipe
          pid = Process.fork do
            begin
              parent_read.close
              parent_write.close
              while !child_read.eof?
                obj = Marshal.load child_read
                Marshal.dump func.call(obj, num), child_write
              end
            rescue Exception => e
              begin
                Marshal.dump WrappedException.new(e), child_write
              rescue Errno::EPIPE
                nil
              end
            ensure
              child_read.close
              child_write.close
            end
          end
          child_read.close
          child_write.close
          JobHandler.new pid, parent_read, parent_write
        end
      end
def prepare_workers ( size , func ) @workers = size . times . map do | num | child_read , parent_write = IO . pipe parent_read , child_write = IO . pipe pid = Process . fork do begin parent_read . close parent_write . close while ! child_read . eof? obj = Marshal . load child_read Marshal . dump func . call ( obj , num ) , child_write end rescue Exception => e begin Marshal . dump WrappedException . new ( e ) , child_write rescue Errno :: EPIPE nil end ensure child_read . close child_write . close end end child_read . close child_write . close JobHandler . new pid , parent_read , parent_write end end
Start forked workers for downloading gems.
Start forked workers for downloading gems .
size
Size of worker pool
Size of worker pool
func
Job that should be executed in the worker
Job that should be executed in the worker