parallel 1.17.0 → 1.20.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
  SHA256:
3
- metadata.gz: a6b2d803fd3a136456287d19f88a5986742beed7246f587491992661235e43c2
4
- data.tar.gz: f3ed40c9c16f0a80e524f55c2f50d570d5da69c2f43ddc62023c323ddb968101
3
+ metadata.gz: 1f41f840e7e5128ebbb8d4ea2955b5bc555925ac049184ae1d4323885a3980b9
4
+ data.tar.gz: f9463997e0b890857d1909e6df6c8632b08eb028fc4015541631ca275d1fabfb
5
5
  SHA512:
6
- metadata.gz: b5534907c40e98488528ed8c9bc08ae1eab61b5b8ec1ce9d1b02b40687d08a6f19f3721e962273674994654dbe7a55b8df05ff905342e0fb28ff810a6036d958
7
- data.tar.gz: d0b9f65e4a85636f8b464605b9b53de89ff529139801a5f8a8c7259783bce45eb1791c43218ba9ec3950e04e00a14f40b38c6079b52375d1c50f34a8db16c109
6
+ metadata.gz: '0581d59c3d38af4fefdd761264899f9661a3c28e8a4d3c9683f7e93c2295313e53d518263a6b4d04fcbb9a57eb55dfe3854e8c27f9f4e378641823eea2aada72'
7
+ data.tar.gz: f77d00250586ada81bddfc2dd47e4895a526215549cee3728f31a927dd617a3a4d2bca7e72d9c7ff3c481e3a4488933c490153d0ef7dec97dc6a5cdd6bc513ed
@@ -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,16 +1,14 @@
1
1
  require 'etc'
2
2
 
3
3
  module Parallel
4
+ # TODO: inline this method into parallel.rb and kill physical_processor_count in next major release
4
5
  module ProcessorCount
5
- # Number of processors seen by the OS and used for process scheduling. It's just wrapper for Etc.nprocessors
6
+ # Number of processors seen by the OS, used for process scheduling
6
7
  def processor_count
7
- @processor_count ||= begin
8
- Etc.nprocessors
9
- end
8
+ @processor_count ||= Integer(ENV['PARALLEL_PROCESSOR_COUNT'] || Etc.nprocessors)
10
9
  end
11
10
 
12
11
  # Number of physical processor cores on the current system.
13
- #
14
12
  def physical_processor_count
15
13
  @physical_processor_count ||= begin
16
14
  ppc = case RbConfig::CONFIG["target_os"]
@@ -1,3 +1,3 @@
1
1
  module Parallel
2
- VERSION = Version = '1.17.0'
2
+ VERSION = Version = '1.20.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.17.0
4
+ version: 1.20.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: 2019-04-01 00:00:00.000000000 Z
11
+ date: 2020-11-07 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.0/Readme.md
29
+ source_code_uri: https://github.com/grosser/parallel/tree/v1.20.0
30
+ wiki_uri: https://github.com/grosser/parallel/wiki
27
31
  post_install_message:
28
32
  rdoc_options: []
29
33
  require_paths:
@@ -32,15 +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.5'
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
- rubyforge_project:
43
- rubygems_version: 2.7.6
46
+ rubygems_version: 3.1.3
44
47
  signing_key:
45
48
  specification_version: 4
46
49
  summary: Run any kind of code in parallel processes