parallel 1.5.1 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4485e35ba1d52d6b8267884c3371533ca3e76fdc
4
- data.tar.gz: b6e4de966f97b0c09cbb8c561efc275de370bed2
3
+ metadata.gz: 0f363b126a1d42e09e74864a71c940edaf139d79
4
+ data.tar.gz: a8976de6367828f3ef06b8eb81822515817b1afc
5
5
  SHA512:
6
- metadata.gz: e024ac38c60e101d73719bb368ef6ec482f7fac471dc2a72dfe0b760ec12e29f75864bd35d1e483ca478fe0e2a594e0cd021d046bf048aaea602ac334aaa9e59
7
- data.tar.gz: fd4fa3446693012160debe76cc48a1abd0c1d80632b94cf2189b375e2202e8c5fec2af8dd4e689414b3fb399b25379edc8f890b2d472a4edfb5e6866a1b7f07f
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(things, options)
127
- return yield if RUBY_ENGINE == "jruby"
128
-
129
- begin
130
- @to_be_killed ||= []
131
- old_interrupt = nil
132
- signal = options.fetch(:interrupt_signal, INTERRUPT_SIGNAL)
133
-
134
- if @to_be_killed.empty?
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
- @to_be_killed << things
138
+ @to_be_killed << pids
142
139
 
143
- yield
144
- ensure
145
- @to_be_killed.pop # free threads for GC and do not kill pids that could be used for new processes
146
- restore_interrupt(old_interrupt, signal) if @to_be_killed.empty?
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
- if thing.is_a?(Thread)
152
- thing.kill
153
- else
154
- begin
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, options = extract_count_from_options(options)
189
-
190
- out = []
191
- threads = []
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
- UserInterruptHandler.kill(w.thread)
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
@@ -1,3 +1,3 @@
1
1
  module Parallel
2
- VERSION = Version = '1.5.1'
2
+ VERSION = Version = '1.6.0'
3
3
  end
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.5.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-25 00:00:00.000000000 Z
11
+ date: 2015-05-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: michael@grosser.it