GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||
GeezerVison is showing github.com — bpo-30581: Windows: os.cpu_count() returns wrong number of processors by crwilcox · Pull Request #2934 · python/cpython Conversation
|
|
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA). Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. Thanks again to your contribution and we look forward to looking at it! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…ount API on Windows calls to os.cpu_count()
7e6a49c to
73adde2
Compare
| /* Vista is supported and the GetMaximumProcessorCount API is Win7+ | ||
| Need to fallback to Vista behavior if this call isn't present */ | ||
| HINSTANCE hKernel32; | ||
| hKernel32 = GetModuleHandleW(L"KERNEL32"); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Does the handle need to be closed after using it?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Other places in posixmodule use this but on closer inspection they are all in methods.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
No, GetModuleHandle does not increase the refcount on the module (it also only works on already-loaded modules, but kernel32 is guaranteed to be there).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| *(FARPROC*)&_GetMaximumProcessorCount = GetProcAddress(hKernel32, | ||
| "GetMaximumProcessorCount"); | ||
| if (_GetMaximumProcessorCount != NULL) { | ||
| ncpu = _GetMaximumProcessorCount(ALL_PROCESSOR_GROUPS); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Is ALL_PROCESSOR_GROUPS always defined at compile-time, even before Windows 7?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think this may be just windows 7 forward. I know the result needs to run on Pre-Windows 7, does it also need to compile?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
In the Windows 10 SDK (which is required) the symbol is always defined. We filter APIs to those available on Vista, but that symbol is not excluded when you do that.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This still requires a NEWS.d entry, and the documentation should be updated to indicate:
I don't believe the latter point is a problem - the current behaviour of the API has the same issue. This falls into the same category as sys.getwindowsversion() reporting what the operating system provides, even when this is incorrect (e.g. Python 2.7 will always return 6.2 even on Windows 10, and the OS also shims certain APIs to behave like the previous version). Since the process is limited by the OS to only 32 CPUs, the os module API should reflect that limit.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Before merging please consider my comment here: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@giampaolo, I had responded. Is there something I didn't address? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@giampaolo, do you have more concerns here? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry for the delay (I've been backpacking / travelling through China). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thank you @crwilcox ! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…python#2934) * Fixes python#30581 by adding a path to use newer GetMaximumProcessorCount API on Windows calls to os.cpu_count() * Add NEWS.d entry for bpo-30581, os.cpu_count on Windows. * Tweak NEWS entry
…python#2934) * Fixes python#30581 by adding a path to use newer GetMaximumProcessorCount API on Windows calls to os.cpu_count() * Add NEWS.d entry for bpo-30581, os.cpu_count on Windows. * Tweak NEWS entry
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.