class Parallel::Worker

Attributes

pid[R]
read[R]
thread[RW]
write[R]

Public Class Methods

new(read, write, pid) click to toggle source
# File lib/parallel.rb, line 55
def initialize(read, write, pid)
  @read = read
  @write = write
  @pid = pid
end

Public Instance Methods

close_pipes() click to toggle source

might be passed to started_processes and simultaneously closed by another thread when running in isolation mode, so we have to check if it is closed before closing

# File lib/parallel.rb, line 68
def close_pipes
  read.close unless read.closed?
  write.close unless write.closed?
end
stop() click to toggle source
# File lib/parallel.rb, line 61
def stop
  close_pipes
  wait # if it goes zombie, rather wait here to be able to debug
end
work(data) click to toggle source
# File lib/parallel.rb, line 73
def work(data)
  begin
    Marshal.dump(data, write)
  rescue Errno::EPIPE
    raise DeadWorker
  end

  result = begin
    Marshal.load(read)
  rescue EOFError
    raise DeadWorker
  end
  raise result.exception if result.is_a?(ExceptionWrapper)
  result
end

Private Instance Methods

wait() click to toggle source
# File lib/parallel.rb, line 91
def wait
  Process.wait(pid)
rescue Interrupt
  # process died
end