parallel 1.5.1 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/parallel.rb +25 -56
- data/lib/parallel/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f363b126a1d42e09e74864a71c940edaf139d79
|
4
|
+
data.tar.gz: a8976de6367828f3ef06b8eb81822515817b1afc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a78ebb2abf7b12749b4ffb318eb70b8b04f00af516dcf438423080a26136bd2a87a097e9b593130294eaf4e9a1e97a754da7c8f7a7a46c7d7b84f5446bdd224
|
7
|
+
data.tar.gz: 3eb8871382f2669e89fecca80bc2dfe198c05df133795e55fd12bd283d0760d7a9c5035c2abc337431b57048647b343ea9022a3ca83bf4da875c53d8a47c3b0c
|
data/lib/parallel.rb
CHANGED
@@ -123,41 +123,31 @@ module Parallel
|
|
123
123
|
|
124
124
|
class << self
|
125
125
|
# kill all these pids or threads if user presses Ctrl+c
|
126
|
-
def kill_on_ctrl_c(
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
old_interrupt = trap_interrupt(signal) do
|
136
|
-
$stderr.puts 'Parallel execution interrupted, exiting ...'
|
137
|
-
@to_be_killed.flatten.compact.each { |thing| kill(thing) }
|
138
|
-
end
|
126
|
+
def kill_on_ctrl_c(pids, options)
|
127
|
+
@to_be_killed ||= []
|
128
|
+
old_interrupt = nil
|
129
|
+
signal = options.fetch(:interrupt_signal, INTERRUPT_SIGNAL)
|
130
|
+
|
131
|
+
if @to_be_killed.empty?
|
132
|
+
old_interrupt = trap_interrupt(signal) do
|
133
|
+
$stderr.puts 'Parallel execution interrupted, exiting ...'
|
134
|
+
@to_be_killed.flatten.each { |pid| kill(pid) }
|
139
135
|
end
|
136
|
+
end
|
140
137
|
|
141
|
-
|
138
|
+
@to_be_killed << pids
|
142
139
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
end
|
140
|
+
yield
|
141
|
+
ensure
|
142
|
+
@to_be_killed.pop # do not kill pids that could be used for new processes
|
143
|
+
restore_interrupt(old_interrupt, signal) if @to_be_killed.empty?
|
148
144
|
end
|
149
145
|
|
150
146
|
def kill(thing)
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
Process.kill(:KILL, thing)
|
156
|
-
rescue Errno::ESRCH
|
157
|
-
# some linux systems already automatically killed the children at this point
|
158
|
-
# so we just ignore them not being there
|
159
|
-
end
|
160
|
-
end
|
147
|
+
Process.kill(:KILL, thing)
|
148
|
+
rescue Errno::ESRCH
|
149
|
+
# some linux systems already automatically killed the children at this point
|
150
|
+
# so we just ignore them not being there
|
161
151
|
end
|
162
152
|
|
163
153
|
private
|
@@ -185,20 +175,10 @@ module Parallel
|
|
185
175
|
|
186
176
|
class << self
|
187
177
|
def in_threads(options={:count => 2})
|
188
|
-
count,
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
count.times do |i|
|
194
|
-
threads[i] = Thread.new do
|
195
|
-
out[i] = yield(i)
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
UserInterruptHandler.kill_on_ctrl_c(threads, options) { wait_for_threads(threads) }
|
200
|
-
|
201
|
-
out
|
178
|
+
count, _ = extract_count_from_options(options)
|
179
|
+
Array.new(count).each_with_index.map do |_, i|
|
180
|
+
Thread.new { yield(i) }
|
181
|
+
end.map!(&:value)
|
202
182
|
end
|
203
183
|
|
204
184
|
def in_processes(options = {}, &block)
|
@@ -291,6 +271,7 @@ module Parallel
|
|
291
271
|
end
|
292
272
|
|
293
273
|
def work_in_threads(job_factory, options, &block)
|
274
|
+
raise "interrupt_signal is no longer supported for threads" if options[:interrupt_signal]
|
294
275
|
results = []
|
295
276
|
exception = nil
|
296
277
|
|
@@ -335,7 +316,7 @@ module Parallel
|
|
335
316
|
exception = e
|
336
317
|
if Parallel::Kill === exception
|
337
318
|
(workers - [worker]).each do |w|
|
338
|
-
|
319
|
+
w.thread.kill
|
339
320
|
UserInterruptHandler.kill(w.pid)
|
340
321
|
end
|
341
322
|
end
|
@@ -396,18 +377,6 @@ module Parallel
|
|
396
377
|
end
|
397
378
|
end
|
398
379
|
|
399
|
-
def wait_for_threads(threads)
|
400
|
-
interrupted = threads.compact.map do |t|
|
401
|
-
begin
|
402
|
-
t.join
|
403
|
-
nil
|
404
|
-
rescue Interrupt => e
|
405
|
-
e # thread died, do not stop other threads
|
406
|
-
end
|
407
|
-
end.compact
|
408
|
-
raise interrupted.first if interrupted.first
|
409
|
-
end
|
410
|
-
|
411
380
|
def handle_exception(exception, results)
|
412
381
|
return nil if [Parallel::Break, Parallel::Kill].include? exception.class
|
413
382
|
raise exception if exception
|
data/lib/parallel/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parallel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Grosser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: michael@grosser.it
|