GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-30581: Windows: os.cpu_count() returns wrong number of processors by crwilcox · Pull Request #2934 · python/cpython

Conversation

@crwilcox

@crwilcox crwilcox commented Jul 28, 2017 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

os.cpu_count() returns wrong number of processors on system with > 64 logical processors

https://bugs.python.org/issue30581

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@the-knights-who-say-ni

the-knights-who-say-ni commented Jul 28, 2017

Copy link
Copy Markdown

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!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@the-knights-who-say-ni the-knights-who-say-ni added the CLA not signed label Jul 28, 2017
@crwilcox
Fixes python#30581 by adding a path to use newer GetMaximumProcessorC…
73adde2
…ount API on Windows calls to os.cpu_count()
@crwilcox
crwilcox force-pushed the bug/windows-processor-counts branch from 7e6a49c to 73adde2 Compare July 28, 2017 16:46
pitrou
pitrou reviewed Jul 29, 2017
View reviewed changes
Comment thread Modules/posixmodule.c
/* 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");

@pitrou pitrou Jul 29, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@crwilcox crwilcox Jul 29, 2017

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@zooba zooba Aug 2, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
pitrou
pitrou reviewed Jul 29, 2017
View reviewed changes
Comment thread Modules/posixmodule.c
*(FARPROC*)&_GetMaximumProcessorCount = GetProcAddress(hKernel32,
"GetMaximumProcessorCount");
if (_GetMaximumProcessorCount != NULL) {
ncpu = _GetMaximumProcessorCount(ALL_PROCESSOR_GROUPS);

@pitrou pitrou Jul 29, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@crwilcox crwilcox Jul 29, 2017

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@zooba zooba Aug 2, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@pitrou
pitrou requested a review from zooba July 29, 2017 10:16
@Mariatta Mariatta removed the CLA not signed label Jul 31, 2017
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Jul 31, 2017
zooba
zooba approved these changes Aug 2, 2017
View reviewed changes

@zooba zooba left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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:

  • the behaviour of the function has changed on Windows
  • the fact that a 32-bit interpreter on 64-bit Windows will never return (nor have access to) more than 32 CPUs

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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@crwilcox
Add NEWS.d entry for bpo-30581, os.cpu_count on Windows.
ef1b704
@giampaolo

giampaolo commented Aug 4, 2017

Copy link
Copy Markdown
Contributor

Before merging please consider my comment here:
http://bugs.python.org/issue30581#msg299477

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@crwilcox

crwilcox commented Aug 4, 2017

Copy link
Copy Markdown
Contributor Author

@giampaolo, I had responded. Is there something I didn't address?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pitrou

pitrou commented Aug 29, 2017

Copy link
Copy Markdown
Member

@giampaolo, do you have more concerns here?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@giampaolo

giampaolo commented Aug 30, 2017

Copy link
Copy Markdown
Contributor

Sorry for the delay (I've been backpacking / travelling through China).
Considering os.cpu_count() is not supposed to return the number of usable CPUs (as I first erroneously thought) the patch LGTM.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

giampaolo
giampaolo approved these changes Aug 30, 2017
View reviewed changes
@bedevere-bot bedevere-bot added the awaiting merge label Aug 30, 2017
@pitrou
Tweak NEWS entry
780ea3c
@pitrou
pitrou merged commit c67bae0 into python:master Aug 30, 2017
@pitrou

pitrou commented Aug 30, 2017

Copy link
Copy Markdown
Member

Thank you @crwilcox !

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

crwilcox added a commit to crwilcox/cpython that referenced this pull request Sep 1, 2017
@crwilcox
bpo-30581: Windows: os.cpu_count() returns wrong number of processors (…
e6374bc
…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
@crwilcox crwilcox mentioned this pull request Sep 1, 2017
bpo-30581: Backport to 3.6: Windows: os.cpu_count() returns wrong number of processors #3267
Merged
pitrou pushed a commit that referenced this pull request Sep 1, 2017
@crwilcox @pitrou
bpo-30581: Windows: os.cpu_count() returns wrong number of processors (…
58521fd
…#2934) (#3267)

* Fixes #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
GadgetSteve pushed a commit to GadgetSteve/cpython that referenced this pull request Sep 10, 2017
@crwilcox @GadgetSteve
bpo-30581: Windows: os.cpu_count() returns wrong number of processors (…
2da135d
…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
@Mariatta Mariatta removed the awaiting merge label Oct 8, 2017
@arhadthedev arhadthedev changed the title bpo-30581: Windows: os.cpu_count() returns wrong number of processors empty Apr 25, 2023
@arhadthedev arhadthedev changed the title empty bpo-30581: Windows: os.cpu_count() returns wrong number of processors Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@pitrou pitrou pitrou left review comments
@giampaolo giampaolo giampaolo approved these changes
@zooba zooba zooba approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@crwilcox @the-knights-who-say-ni @giampaolo @pitrou @zooba @Mariatta @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.