Class: Parallel::Worker
- Inherits:
-
Object
- Object
- Parallel::Worker
- Defined in:
- lib/parallel.rb
Instance Attribute Summary collapse
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#read ⇒ Object
readonly
Returns the value of attribute read.
-
#thread ⇒ Object
Returns the value of attribute thread.
-
#write ⇒ Object
readonly
Returns the value of attribute write.
Instance Method Summary collapse
-
#close_pipes ⇒ Object
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.
-
#initialize(read, write, pid, serializer) ⇒ Worker
constructor
A new instance of Worker.
- #stop ⇒ Object
- #work(data) ⇒ Object
Constructor Details
#initialize(read, write, pid, serializer) ⇒ Worker
Returns a new instance of Worker.
67 68 69 70 71 72 |
# File 'lib/parallel.rb', line 67 def initialize(read, write, pid, serializer) @read = read @write = write @pid = pid @serializer = serializer end |
Instance Attribute Details
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
64 65 66 |
# File 'lib/parallel.rb', line 64 def pid @pid end |
#read ⇒ Object (readonly)
Returns the value of attribute read.
64 65 66 |
# File 'lib/parallel.rb', line 64 def read @read end |
#thread ⇒ Object
Returns the value of attribute thread.
65 66 67 |
# File 'lib/parallel.rb', line 65 def thread @thread end |
#write ⇒ Object (readonly)
Returns the value of attribute write.
64 65 66 |
# File 'lib/parallel.rb', line 64 def write @write end |
Instance Method Details
#close_pipes ⇒ Object
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
81 82 83 84 |
# File 'lib/parallel.rb', line 81 def close_pipes read.close unless read.closed? write.close unless write.closed? end |
#stop ⇒ Object
74 75 76 77 |
# File 'lib/parallel.rb', line 74 def stop close_pipes wait # if it goes zombie, rather wait here to be able to debug end |
#work(data) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/parallel.rb', line 86 def work(data) begin @serializer.dump(data, write) rescue Errno::EPIPE raise DeadWorker end result = begin @serializer.load(read) rescue EOFError raise DeadWorker end raise result.exception if result.is_a?(ExceptionWrapper) result end |