-
Notifications
You must be signed in to change notification settings - Fork 254
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
break on ctrl+c #183
Comments
you can do your own trapping and then raise a Parallel::Break On Mon, Jul 25, 2016 at 2:09 PM, Robert Riemann notifications@github.com
|
I've tried something like this: begin
measurements = Parallel.map(measurements, progress: "Simulating") do |measurement|
trap("SIGINT") { Parallel::Break }
measurement[:cmd] = "java -jar app.jar --present-peers #{measurement[:presentPeers]} --deadline #{deadline} --byzantine-peers #{measurement[:byzantinePeers]} --seed #{measurement[:seed]} --log=jmsg.thres:error 2> /dev/null"
measurement[:result] = `#{measurement[:cmd]}`.to_f
measurement[:exitcode] = $?.to_i
pp measurement
measurement
end
rescue Interrupt
end However, when |
oh yeah ... break makes it return nil ... as rubies break does ... should be able to use the finish hook ... require 'parallel'
done = []
finish = lambda { |_,_,x| done << x; puts "DONE #{done.inspect}" }
begin
Parallel.each(Array.new(10), finish: finish) { |i| sleep 1; 2 }
rescue Interrupt
end
puts "end #{done.inspect}"
ruby xxx.rb
DONE [2]
DONE [2, 2]
DONE [2, 2, 2]
DONE [2, 2, 2, 2]
^CParallel execution interrupted, exiting ...
end [2, 2, 2, 2] |
Hello,
I use Parallel.map to run some computations in parallel. Is it possible to trap ctrl+c or ctrl+d and break after current tasks are done? So far, the script stops entirely and my intermediate results are not saved.
The text was updated successfully, but these errors were encountered: