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) ⇒ Worker
constructor
A new instance of Worker.
- #stop ⇒ Object
- #work(data) ⇒ Object
Constructor Details
#initialize(read, write, pid) ⇒ Worker
Returns a new instance of Worker.
55 56 57 58 59 |
# File 'lib/parallel.rb', line 55 def initialize(read, write, pid) @read = read @write = write @pid = pid end |
Instance Attribute Details
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
52 53 54 |
# File 'lib/parallel.rb', line 52 def pid @pid end |
#read ⇒ Object (readonly)
Returns the value of attribute read.
52 53 54 |
# File 'lib/parallel.rb', line 52 def read @read end |
#thread ⇒ Object
Returns the value of attribute thread.
53 54 55 |
# File 'lib/parallel.rb', line 53 def thread @thread end |
#write ⇒ Object (readonly)
Returns the value of attribute write.
52 53 54 |
# File 'lib/parallel.rb', line 52 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
68 69 70 71 |
# File 'lib/parallel.rb', line 68 def close_pipes read.close unless read.closed? write.close unless write.closed? end |
#stop ⇒ Object
61 62 63 64 |
# 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) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# 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 |