Number of processors
-
Hi,
Is there a way to get number of processors with Ruby in Sketchup.
I've found on internet solutions like thisrequire 'win32ole' wmi = WIN32OLE.connect("winmgmts;//") num = wmi.ExecQuery("select * from Win32_ComputerSystem").NumberOfProcessorsproblem is when I run this in Sketchup I get error
- unknown property or method `NumberOfProcessors' HRESULT error code;0x80020006 Unknown name. Error; #<WIN32OLERuntimeError; unknown property or method `NumberOfProcessors' HRESULT error code;0x80020006 Unknown name.>I'm using win32ole posted here: [Plugin Library] Win32API and Win32OLE so files
-
Is this any help?
# Returns the number of processor for Linux, OS X or Windows. def number_of_processors if RUBY_PLATFORM =~ /linux/ return `cat /proc/cpuinfo | grep processor | wc -l`.to_i elsif RUBY_PLATFORM =~ /darwin/ return `sysctl -n hw.logicalcpu`.to_i elsif RUBY_PLATFORM =~ /win32/ # this works for windows 2000 or greater require 'win32ole' wmi = WIN32OLE.connect("winmgmts;//") wmi.ExecQuery("select * from Win32_ComputerSystem").each do |system| begin processors = system.NumberOfLogicalProcessors rescue processors = 0 end return [system.NumberOfProcessors, processors].max end end raise "can't determine 'number_of_processors' for '#{RUBY_PLATFORM}'" end -
On Windows, an environment var is set for the number of processors:
num = ENV['NUMBER_OF_PROCESSORS'].to_i -
num = ENV['NUMBER_OF_PROCESSORS'].to_iis much easier than the other way and should be fine unless you want to have a cross-platform solution... We don't know if MAC has the same ENV variable 0 - some references are similar to PC, while others can be the same ??
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement