parallel 1.18.0 → 1.20.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '07982de0b997f714be6d852d131b956890732c67693ea444cb387d116ce3c28a'
4
- data.tar.gz: af82ce6875dc07e1260a5a0fa612eb277fd6205c08c546e87ff1acfe6ee12565
3
+ metadata.gz: fa334cb0d83b8049f260a5e6724d2fd0e65768f85afd0968a2af05d55dda4e0e
4
+ data.tar.gz: 7ba3ade3a7af4bcfe5944b8d7313b5ec6e4074d27755a83f95e4f8a01d77261e
5
5
  SHA512:
6
- metadata.gz: 02ef44d1053d7cd986acb9e8c31f6784c81749fb28cb3d984eeea27bf787f3927c87f5d0bea1f2d462b938a744685ce5aa7b3061e082279e767364395bb08062
7
- data.tar.gz: 5a245449c881801fd3e7051dd040db977ddd6b80a488c31ec26300653c81468448c6e729d1123b3ece94e24c230877225e4edca7037ba4ccfb5dd37eca6f649a
6
+ metadata.gz: d470562bd90ab80c66f69b9c1ab016f737bf52e091ac3027c51ea7482eaecd3bd3c186daab756c5d4276b9fb54f0e80f149a8071dc17c31a321ff4fc4d369600
7
+ data.tar.gz: f01bf1c3a052579c11c3097b02b02a4a30c8e881dbb4916c3ceba6f122aab3a40c276a1de82f7ea7d3790eeff2f994bd20283361151439a3d57b025bdd24dfc8
@@ -3,15 +3,21 @@ require 'parallel/version'
3
3
  require 'parallel/processor_count'
4
4
 
5
5
  module Parallel
6
- extend Parallel::ProcessorCount
6
+ extend ProcessorCount
7
+
8
+ Stop = Object.new.freeze
7
9
 
8
10
  class DeadWorker < StandardError
9
11
  end
10
12
 
11
13
  class Break < StandardError
14
+ attr_reader :value
15
+ def initialize(value = nil)
16
+ @value = value
17
+ end
12
18
  end
13
19
 
14
- class Kill < StandardError
20
+ class Kill < Break
15
21
  end
16
22
 
17
23
  class UndumpableException < StandardError
@@ -22,8 +28,6 @@ module Parallel
22
28
  end
23
29
  end
24
30
 
25
- Stop = Object.new.freeze
26
-
27
31
  class ExceptionWrapper
28
32
  attr_reader :exception
29
33
  def initialize(exception)
@@ -102,7 +106,7 @@ module Parallel
102
106
  item, index = @mutex.synchronize do
103
107
  return if @stopped
104
108
  item = @lambda.call
105
- @stopped = (item == Parallel::Stop)
109
+ @stopped = (item == Stop)
106
110
  return if @stopped
107
111
  [item, @index += 1]
108
112
  end
@@ -201,14 +205,15 @@ module Parallel
201
205
 
202
206
  class << self
203
207
  def in_threads(options={:count => 2})
208
+ threads = []
209
+ count, _ = extract_count_from_options(options)
210
+
204
211
  Thread.handle_interrupt(Exception => :never) do
205
212
  begin
206
- threads = []
207
- count, _ = extract_count_from_options(options)
208
- count.times do |i|
209
- threads << Thread.new { yield(i) }
210
- end
211
213
  Thread.handle_interrupt(Exception => :immediate) do
214
+ count.times do |i|
215
+ threads << Thread.new { yield(i) }
216
+ end
212
217
  threads.map(&:value)
213
218
  end
214
219
  ensure
@@ -229,12 +234,12 @@ module Parallel
229
234
 
230
235
  def any?(*args, &block)
231
236
  raise "You must provide a block when calling #any?" if block.nil?
232
- !each(*args) { |*a| raise Parallel::Kill if block.call(*a) }
237
+ !each(*args) { |*a| raise Kill if block.call(*a) }
233
238
  end
234
239
 
235
240
  def all?(*args, &block)
236
241
  raise "You must provide a block when calling #all?" if block.nil?
237
- !!each(*args) { |*a| raise Parallel::Kill unless block.call(*a) }
242
+ !!each(*args) { |*a| raise Kill unless block.call(*a) }
238
243
  end
239
244
 
240
245
  def each_with_index(array, options={}, &block)
@@ -269,16 +274,18 @@ module Parallel
269
274
  options[:return_results] = (options[:preserve_results] != false || !!options[:finish])
270
275
  add_progress_bar!(job_factory, options)
271
276
 
272
- results = if size == 0
273
- work_direct(job_factory, options, &block)
274
- elsif method == :in_threads
275
- work_in_threads(job_factory, options.merge(:count => size), &block)
276
- else
277
- work_in_processes(job_factory, options.merge(:count => size), &block)
278
- end
279
- if results
280
- options[:return_results] ? results : source
281
- end
277
+ result =
278
+ if size == 0
279
+ work_direct(job_factory, options, &block)
280
+ elsif method == :in_threads
281
+ work_in_threads(job_factory, options.merge(:count => size), &block)
282
+ else
283
+ work_in_processes(job_factory, options.merge(:count => size), &block)
284
+ end
285
+
286
+ return result.value if result.is_a?(Break)
287
+ raise result if result.is_a?(Exception)
288
+ options[:return_results] ? result : source
282
289
  end
283
290
 
284
291
  def map_with_index(array, options={}, &block)
@@ -339,7 +346,7 @@ module Parallel
339
346
  rescue
340
347
  exception = $!
341
348
  end
342
- handle_exception(exception, results)
349
+ exception || results
343
350
  ensure
344
351
  self.worker_number = nil
345
352
  end
@@ -366,7 +373,7 @@ module Parallel
366
373
  end
367
374
  end
368
375
 
369
- handle_exception(exception, results)
376
+ exception || results
370
377
  end
371
378
 
372
379
  def work_in_processes(job_factory, options, &blk)
@@ -400,7 +407,7 @@ module Parallel
400
407
  results_mutex.synchronize { results[index] = result } # arrays are not threads safe on jRuby
401
408
  rescue StandardError => e
402
409
  exception = e
403
- if Parallel::Kill === exception
410
+ if Kill === exception
404
411
  (workers - [worker]).each do |w|
405
412
  w.thread.kill if w.thread
406
413
  UserInterruptHandler.kill(w.pid)
@@ -413,8 +420,7 @@ module Parallel
413
420
  end
414
421
  end
415
422
  end
416
-
417
- handle_exception(exception, results)
423
+ exception || results
418
424
  end
419
425
 
420
426
  def replace_worker(job_factory, workers, i, options, blk)
@@ -469,7 +475,10 @@ module Parallel
469
475
  item, index = job_factory.unpack(data)
470
476
  result = begin
471
477
  call_with_index(item, index, options, &block)
472
- rescue
478
+ # https://github.com/rspec/rspec-support/blob/673133cdd13b17077b3d88ece8d7380821f8d7dc/lib/rspec/support.rb#L132-L140
479
+ rescue NoMemoryError, SignalException, Interrupt, SystemExit
480
+ raise $!
481
+ rescue Exception
473
482
  ExceptionWrapper.new($!)
474
483
  end
475
484
  begin
@@ -480,12 +489,6 @@ module Parallel
480
489
  end
481
490
  end
482
491
 
483
- def handle_exception(exception, results)
484
- return nil if [Parallel::Break, Parallel::Kill].include? exception.class
485
- raise exception if exception
486
- results
487
- end
488
-
489
492
  # options is either a Integer or a Hash with :count
490
493
  def extract_count_from_options(options)
491
494
  if options.is_a?(Hash)
@@ -1,3 +1,3 @@
1
1
  module Parallel
2
- VERSION = Version = '1.18.0'
2
+ VERSION = Version = '1.20.1'
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.18.0
4
+ version: 1.20.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-06 00:00:00.000000000 Z
11
+ date: 2020-11-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: michael@grosser.it
@@ -23,7 +23,11 @@ files:
23
23
  homepage: https://github.com/grosser/parallel
24
24
  licenses:
25
25
  - MIT
26
- metadata: {}
26
+ metadata:
27
+ bug_tracker_uri: https://github.com/grosser/parallel/issues
28
+ documentation_uri: https://github.com/grosser/parallel/blob/v1.20.1/Readme.md
29
+ source_code_uri: https://github.com/grosser/parallel/tree/v1.20.1
30
+ wiki_uri: https://github.com/grosser/parallel/wiki
27
31
  post_install_message:
28
32
  rdoc_options: []
29
33
  require_paths:
@@ -32,14 +36,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
32
36
  requirements:
33
37
  - - ">="
34
38
  - !ruby/object:Gem::Version
35
- version: '2.2'
39
+ version: '2.4'
36
40
  required_rubygems_version: !ruby/object:Gem::Requirement
37
41
  requirements:
38
42
  - - ">="
39
43
  - !ruby/object:Gem::Version
40
44
  version: '0'
41
45
  requirements: []
42
- rubygems_version: 3.0.3
46
+ rubygems_version: 3.1.3
43
47
  signing_key:
44
48
  specification_version: 4
45
49
  summary: Run any kind of code in parallel processes