Skip to content
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
11 changes: 11 additions & 0 deletions lib/parallel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ def initialize(value = nil)
super()
@value = value
end

# marshal_dump that is used for ruby exceptions
# avoid dumping the cause since nobody needs that and it can include undumpable exceptions
def _dump(_depth)
Marshal.dump(@value)
end

# marshal_load that is used for ruby exceptions
def self._load(data)
new(Marshal.load(data))
end
end

class Kill < Break
Expand Down
20 changes: 20 additions & 0 deletions spec/cases/parallel_break_with_undumpable_cause.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true
require './spec/cases/helper'

class UndumpableCauseError < StandardError
def initialize
super("bad")
@binding = binding # can't be dumped when it is the cause
end
end

begin
x = Parallel.in_processes(2) do
raise UndumpableCauseError
rescue StandardError
raise Parallel::Break, "hello"
end
puts "Result: #{x}"
rescue StandardError => e
puts "Error: #{e.class}: #{e.message}"
end
5 changes: 5 additions & 0 deletions spec/parallel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ def cpus
out.should == "NOTHING WAS RAISED"
end

it "can handle Break with an undumpable cause" do
out = ruby("spec/cases/parallel_break_with_undumpable_cause.rb").strip
out.should == "Result: hello"
end

it 'can handle to high fork rate' do
next if RbConfig::CONFIG["target_os"].include?("darwin1") # kills macs for some reason
ruby("spec/cases/parallel_high_fork_rate.rb").should == 'OK'
Expand Down
Loading