parallel 1.23.0 → 1.26.1
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 +4 -4
- data/lib/parallel/version.rb +1 -1
- data/lib/parallel.rb +64 -17
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07e82b1b9dcebf36e66fe30d3aa8fd0624f7782cce1ea60e3e1c5cf906daf19b
|
4
|
+
data.tar.gz: da6d2113751edf198465410d4500a718b915f1fb6a303ce8c0e81c0facf44058
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49f746cc65c27b7aa5811a5b6eb539caabacaec8bd0d8899b12ca50a6e147d09fbe8cb8e49c8452d4dd415e595b32c47f13f149f4344b11fef1314a601a4b768
|
7
|
+
data.tar.gz: d76accec70cea0388ec640652d012a18afa659da706763008290a09e1fa9f763e445cfd9686a9f19fc20443d2d445cfe5bf0ac9dfd4df171f379f5f5f1b155d5
|
data/lib/parallel/version.rb
CHANGED
data/lib/parallel.rb
CHANGED
@@ -24,7 +24,7 @@ module Parallel
|
|
24
24
|
attr_reader :backtrace
|
25
25
|
|
26
26
|
def initialize(original)
|
27
|
-
super
|
27
|
+
super("#{original.class}: #{original.message}")
|
28
28
|
@backtrace = original.backtrace
|
29
29
|
end
|
30
30
|
end
|
@@ -300,12 +300,12 @@ module Parallel
|
|
300
300
|
map(array, options.merge(with_index: true), &block)
|
301
301
|
end
|
302
302
|
|
303
|
-
def flat_map(
|
304
|
-
map(
|
303
|
+
def flat_map(...)
|
304
|
+
map(...).flatten(1)
|
305
305
|
end
|
306
306
|
|
307
|
-
def filter_map(
|
308
|
-
map(
|
307
|
+
def filter_map(...)
|
308
|
+
map(...).compact
|
309
309
|
end
|
310
310
|
|
311
311
|
# Number of physical processor cores on the current system.
|
@@ -328,11 +328,7 @@ module Parallel
|
|
328
328
|
end
|
329
329
|
cores.count
|
330
330
|
when /mswin|mingw/
|
331
|
-
|
332
|
-
result_set = WIN32OLE.connect("winmgmts://").ExecQuery(
|
333
|
-
"select NumberOfCores from Win32_Processor"
|
334
|
-
)
|
335
|
-
result_set.to_enum.collect(&:NumberOfCores).reduce(:+)
|
331
|
+
physical_processor_count_windows
|
336
332
|
else
|
337
333
|
processor_count
|
338
334
|
end
|
@@ -358,8 +354,35 @@ module Parallel
|
|
358
354
|
|
359
355
|
private
|
360
356
|
|
357
|
+
def physical_processor_count_windows
|
358
|
+
# Get-CimInstance introduced in PowerShell 3 or earlier: https://learn.microsoft.com/en-us/previous-versions/powershell/module/cimcmdlets/get-ciminstance?view=powershell-3.0
|
359
|
+
result = run(
|
360
|
+
'powershell -command "Get-CimInstance -ClassName Win32_Processor -Property NumberOfCores ' \
|
361
|
+
'| Select-Object -Property NumberOfCores"'
|
362
|
+
)
|
363
|
+
if !result || $?.exitstatus != 0
|
364
|
+
# fallback to deprecated wmic for older systems
|
365
|
+
result = run("wmic cpu get NumberOfCores")
|
366
|
+
end
|
367
|
+
if !result || $?.exitstatus != 0
|
368
|
+
# Bail out if both commands returned something unexpected
|
369
|
+
warn "guessing pyhsical processor count"
|
370
|
+
processor_count
|
371
|
+
else
|
372
|
+
# powershell: "\nNumberOfCores\n-------------\n 4\n\n\n"
|
373
|
+
# wmic: "NumberOfCores \n\n4 \n\n\n\n"
|
374
|
+
result.scan(/\d+/).map(&:to_i).reduce(:+)
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
378
|
+
def run(command)
|
379
|
+
IO.popen(command, &:read)
|
380
|
+
rescue Errno::ENOENT
|
381
|
+
# Ignore
|
382
|
+
end
|
383
|
+
|
361
384
|
def add_progress_bar!(job_factory, options)
|
362
|
-
if progress_options = options[:progress]
|
385
|
+
if (progress_options = options[:progress])
|
363
386
|
raise "Progressbar can only be used with array like items" if job_factory.size == Float::INFINITY
|
364
387
|
require 'ruby-progressbar'
|
365
388
|
|
@@ -388,7 +411,7 @@ module Parallel
|
|
388
411
|
results = []
|
389
412
|
exception = nil
|
390
413
|
begin
|
391
|
-
while set = job_factory.next
|
414
|
+
while (set = job_factory.next)
|
392
415
|
item, index = set
|
393
416
|
results << with_instrumentation(item, index, options) do
|
394
417
|
call_with_index(item, index, options, &block)
|
@@ -411,7 +434,7 @@ module Parallel
|
|
411
434
|
in_threads(options) do |worker_num|
|
412
435
|
self.worker_number = worker_num
|
413
436
|
# as long as there are more jobs, work on one of them
|
414
|
-
while !exception && set = job_factory.next
|
437
|
+
while !exception && (set = job_factory.next)
|
415
438
|
begin
|
416
439
|
item, index = set
|
417
440
|
result = with_instrumentation item, index, options do
|
@@ -455,7 +478,7 @@ module Parallel
|
|
455
478
|
|
456
479
|
# start
|
457
480
|
ractors.dup.each do |ractor|
|
458
|
-
if set = job_factory.next
|
481
|
+
if (set = job_factory.next)
|
459
482
|
item, index = set
|
460
483
|
instrument_start item, index, options
|
461
484
|
ractor.send [callback, item, index]
|
@@ -466,7 +489,7 @@ module Parallel
|
|
466
489
|
end
|
467
490
|
|
468
491
|
# replace with new items
|
469
|
-
while set = job_factory.next
|
492
|
+
while (set = job_factory.next)
|
470
493
|
item_next, index_next = set
|
471
494
|
done, (exception, result, item, index) = Ractor.select(*ractors)
|
472
495
|
if exception
|
@@ -640,12 +663,36 @@ module Parallel
|
|
640
663
|
end
|
641
664
|
|
642
665
|
def instrument_finish(item, index, result, options)
|
643
|
-
return unless on_finish = options[:finish]
|
666
|
+
return unless (on_finish = options[:finish])
|
667
|
+
return instrument_finish_in_order(item, index, result, options) if options[:finish_in_order]
|
644
668
|
options[:mutex].synchronize { on_finish.call(item, index, result) }
|
645
669
|
end
|
646
670
|
|
671
|
+
# yield results in the order of the input items
|
672
|
+
# needs to use `options` to store state between executions
|
673
|
+
# needs to use `done` index since a nil result would also be valid
|
674
|
+
def instrument_finish_in_order(item, index, result, options)
|
675
|
+
options[:mutex].synchronize do
|
676
|
+
# initialize our state
|
677
|
+
options[:finish_done] ||= []
|
678
|
+
options[:finish_expecting] ||= 0 # we wait for item at index 0
|
679
|
+
|
680
|
+
# store current result
|
681
|
+
options[:finish_done][index] = [item, result]
|
682
|
+
|
683
|
+
# yield all results that are now in order
|
684
|
+
break unless index == options[:finish_expecting]
|
685
|
+
index.upto(options[:finish_done].size).each do |i|
|
686
|
+
break unless (done = options[:finish_done][i])
|
687
|
+
options[:finish_done][i] = nil # allow GC to free this item and result
|
688
|
+
options[:finish].call(done[0], i, done[1])
|
689
|
+
options[:finish_expecting] += 1
|
690
|
+
end
|
691
|
+
end
|
692
|
+
end
|
693
|
+
|
647
694
|
def instrument_start(item, index, options)
|
648
|
-
return unless on_start = options[:start]
|
695
|
+
return unless (on_start = options[:start])
|
649
696
|
options[:mutex].synchronize { on_start.call(item, index) }
|
650
697
|
end
|
651
698
|
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parallel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.26.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Grosser
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description:
|
14
14
|
email: michael@grosser.it
|
15
15
|
executables: []
|
16
16
|
extensions: []
|
@@ -24,10 +24,10 @@ licenses:
|
|
24
24
|
- MIT
|
25
25
|
metadata:
|
26
26
|
bug_tracker_uri: https://github.com/grosser/parallel/issues
|
27
|
-
documentation_uri: https://github.com/grosser/parallel/blob/v1.
|
28
|
-
source_code_uri: https://github.com/grosser/parallel/tree/v1.
|
27
|
+
documentation_uri: https://github.com/grosser/parallel/blob/v1.26.1/Readme.md
|
28
|
+
source_code_uri: https://github.com/grosser/parallel/tree/v1.26.1
|
29
29
|
wiki_uri: https://github.com/grosser/parallel/wiki
|
30
|
-
post_install_message:
|
30
|
+
post_install_message:
|
31
31
|
rdoc_options: []
|
32
32
|
require_paths:
|
33
33
|
- lib
|
@@ -35,15 +35,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
35
35
|
requirements:
|
36
36
|
- - ">="
|
37
37
|
- !ruby/object:Gem::Version
|
38
|
-
version: '2.
|
38
|
+
version: '2.7'
|
39
39
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
41
|
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: '0'
|
44
44
|
requirements: []
|
45
|
-
rubygems_version: 3.
|
46
|
-
signing_key:
|
45
|
+
rubygems_version: 3.4.10
|
46
|
+
signing_key:
|
47
47
|
specification_version: 4
|
48
48
|
summary: Run any kind of code in parallel processes
|
49
49
|
test_files: []
|