Class: Parallel::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/gpack/core/parallel.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(read, write, pid) ⇒ Worker

Returns a new instance of Worker.



137
138
139
# File 'lib/gpack/core/parallel.rb', line 137

def initialize(read, write, pid)
  @read, @write, @pid = read, write, pid
end

Instance Attribute Details

#pidObject (readonly)

Returns the value of attribute pid.



135
136
137
# File 'lib/gpack/core/parallel.rb', line 135

def pid
  @pid
end

#readObject (readonly)

Returns the value of attribute read.



135
136
137
# File 'lib/gpack/core/parallel.rb', line 135

def read
  @read
end

#threadObject

Returns the value of attribute thread.



136
137
138
# File 'lib/gpack/core/parallel.rb', line 136

def thread
  @thread
end

#writeObject (readonly)

Returns the value of attribute write.



135
136
137
# File 'lib/gpack/core/parallel.rb', line 135

def write
  @write
end

Instance Method Details

#close_pipesObject

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



148
149
150
151
# File 'lib/gpack/core/parallel.rb', line 148

def close_pipes
  read.close unless read.closed?
  write.close unless write.closed?
end

#stopObject



141
142
143
144
# File 'lib/gpack/core/parallel.rb', line 141

def stop
  close_pipes
  wait # if it goes zombie, rather wait here to be able to debug
end

#work(data) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/gpack/core/parallel.rb', line 153

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 ExceptionWrapper === result
  result
end