-
-
Notifications
You must be signed in to change notification settings - Fork 32k
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
base: main
Are you sure you want to change the base?
Conversation
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
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
# 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 |
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'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
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 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.
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.
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
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.