diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index a699e0b..3173728 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -12,14 +12,14 @@ jobs: image: mysql strategy: matrix: - ruby: [ '2.7', '3.0', '3.1', '3.2' ] + ruby: [ '2.7', '3.0', '3.1', '3.2', '3.3' ] task: [ 'spec' ] include: - ruby: 2.7 # keep in sync with lowest version task: rubocop name: ${{ matrix.ruby }} rake ${{ matrix.task }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} diff --git a/Gemfile b/Gemfile index 8ca9396..faa9fdb 100644 --- a/Gemfile +++ b/Gemfile @@ -14,4 +14,4 @@ gem 'rubocop-rake' gem 'rubocop-rspec' gem 'mysql2', group: :mysql -gem 'sqlite3' +gem 'sqlite3', '~> 1.4' diff --git a/Gemfile.lock b/Gemfile.lock index faf2145..b998f41 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -26,6 +26,7 @@ GEM json (2.7.1) json (2.7.1-java) language_server-protocol (3.17.0.3) + mini_portile2 (2.8.7) minitest (5.15.0) mysql2 (0.5.6) parser (3.3.0.5) @@ -72,7 +73,8 @@ GEM rubocop-rspec (2.9.0) rubocop (~> 1.19) ruby-progressbar (1.13.0) - sqlite3 (1.4.2) + sqlite3 (1.7.3) + mini_portile2 (~> 2.8.0) tzinfo (2.0.4) concurrent-ruby (~> 1.0) unicode-display_width (2.5.0) @@ -95,7 +97,7 @@ DEPENDENCIES rubocop-rake rubocop-rspec ruby-progressbar - sqlite3 + sqlite3 (~> 1.4) BUNDLED WITH 2.3.12 diff --git a/lib/parallel.rb b/lib/parallel.rb index 59a72dc..82b9ea1 100644 --- a/lib/parallel.rb +++ b/lib/parallel.rb @@ -328,11 +328,7 @@ def physical_processor_count end cores.count when /mswin|mingw/ - require 'win32ole' - result_set = WIN32OLE.connect("winmgmts://").ExecQuery( - "select NumberOfCores from Win32_Processor" - ) - result_set.to_enum.collect(&:NumberOfCores).reduce(:+) + physical_processor_count_windows else processor_count end @@ -358,6 +354,33 @@ def worker_number=(worker_num) private + def physical_processor_count_windows + # 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 + result = run( + 'powershell -command "Get-CimInstance -ClassName Win32_Processor ' \ + '| Select-Object -Property NumberOfCores"' + ) + if !result || $?.exitstatus != 0 + # fallback to deprecated wmic for older systems + result = run("wmic cpu get NumberOfCores") + end + if !result || $?.exitstatus != 0 + # Bail out if both commands returned something unexpected + warn "guessing pyhsical processor count" + processor_count + else + # powershell: "\nNumberOfCores\n-------------\n 4\n\n\n" + # wmic: "NumberOfCores \n\n4 \n\n\n\n" + result.scan(/\d+/).map(&:to_i).reduce(:+) + end + end + + def run(command) + IO.popen(command, &:read) + rescue Errno::ENOENT + # Ignore + end + def add_progress_bar!(job_factory, options) if (progress_options = options[:progress]) raise "Progressbar can only be used with array like items" if job_factory.size == Float::INFINITY diff --git a/spec/parallel_spec.rb b/spec/parallel_spec.rb index 39e2598..2388e28 100644 --- a/spec/parallel_spec.rb +++ b/spec/parallel_spec.rb @@ -736,7 +736,7 @@ def cpus def normalize(result) result = result.sub(/\{(.*)\}/, "\\1").split(", ") result.reject! { |x| x =~ /^(Hash|Array|String)=>(1|-1|-2)$/ } - result.reject! { |x| x =~ /^(Mutex)=>(1)$/ } if RUBY_VERSION < "2.0" + result.reject! { |x| x =~ /^(Thread::Mutex)=>(1)$/ } if RUBY_VERSION >= "3.3" result end