Skip to content

gh-94242: Update calculation of _MAX_WINDOWS_WORKERS #94283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

randomascii
Copy link

@randomascii randomascii commented Jun 26, 2022

The calculation of _MAX_WINDOWS_WORKERS contained two off-by-one errors.
They cancelled each other out so this does not change the value of
_MAX_WINDOWS_WORKERS, just how it is determined. This could avoid future
confusion about where the 61 value comes from.

The calculation of _MAX_WINDOWS_WORKERS contained two off-by-one errors.
They cancelled each other out so this does not change the value of
_MAX_WINDOWS_WORKERS, just how it is determined. This could avoid future
confusion about where the 61 value comes from.

Refs python#94242
@ghost
Copy link

ghost commented Jun 26, 2022

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-bot
Copy link

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@corona10 corona10 requested a review from eryksun June 26, 2022 14:35
@corona10 corona10 self-assigned this Jun 26, 2022
Comment on lines +111 to +116
# It can wait on, at most, 64 objects. There is an overhead of two to three
# objects:
# - the result queue reader
# - the thread wakeup reader
_MAX_WINDOWS_WORKERS = 63 - 2
# - sometimes _PyOS_SigintEvent
_MAX_WINDOWS_WORKERS = 64 - 3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer for the previous line to state that on Windows waiting for processes to finish uses _winapi.WaitForMultipleObjects. Ideally, _winapi.MAXIMUM_WAIT_OBJECTS would be defined, which you'd have to add in Modules/_winapi.c. Then we'd have:

# It can wait on, at most, MAXIMUM_WAIT_OBJECTS - 1 (63) objects. An index of
# the wait list is reserved for the interpreter's SIGINT event. There is an
# additional overhead of two objects:
# - the result queue reader
# - the thread wakeup reader
_MAX_WINDOWS_WORKERS = _winapi.MAXIMUM_WAIT_OBJECTS - 3

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the desire to use _winapi.MAXIMUM_WAIT_OBJECTS but as a casual contributor to cpython I don't want to start altering _winapi.c - it's not practical for me to test such changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could still use MAXIMUM_WAIT_OBJECTS in the comment, and make it clear that the SIGINT overhead is due to the _winapi implementation, not overhead added by this module. For example:

# In Windows, waiting for processes uses _winapi.WaitForMultipleObjects.
# It can wait on, at most, MAXIMUM_WAIT_OBJECTS - 1 (64 - 1) objects because
# it reserves an index of the wait list for the interpreter's SIGINT event.
# There is an additional overhead of two objects:
# - the result queue reader
# - the thread wakeup reader
_MAX_WINDOWS_WORKERS = 64 - 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants