Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure to also rescue non-standard error #269

Merged
merged 3 commits into from
Nov 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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