Skip to content

Commit

Permalink
Merge pull request #269 from RusHibaM/master
Browse files Browse the repository at this point in the history
Make sure to also rescue non-standard error
  • Loading branch information
grosser committed Nov 13, 2019
2 parents 551443c + f88354e commit 064ae07
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/parallel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,9 @@ def process_incoming_jobs(read, write, job_factory, options, &block)
item, index = job_factory.unpack(data)
result = begin
call_with_index(item, index, options, &block)
rescue
rescue SystemExit, SignalException
raise $!
rescue Exception
ExceptionWrapper.new($!)
end
begin
Expand Down
11 changes: 11 additions & 0 deletions spec/cases/exception_raised_in_process.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require './spec/cases/helper'

begin
Parallel.each([1]){ raise Exception }
rescue Parallel::DeadWorker
puts "No, DEAD worker found"
rescue Exception
puts "Yep, rescued the exception"
else
puts "WHOOOPS"
end
4 changes: 4 additions & 0 deletions spec/parallel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,10 @@ def cpus
`ruby spec/cases/exit_in_process.rb 2>&1`.should include "Yep, DEAD"
end

it "should rescue the Exception raised in child process" do
`ruby spec/cases/exception_raised_in_process.rb 2>&1`.should include "Yep, rescued the exception"
end

it 'raises EOF (not DeadWorker) when a worker raises EOF in process' do
`ruby spec/cases/eof_in_process.rb 2>&1`.should include 'Yep, EOF'
end
Expand Down

0 comments on commit 064ae07

Please sign in to comment.