Thanks to visit codestin.com
Credit goes to github.com

Skip to content

GH-118095: Make sure that progress is made if there are pending calls being handled. #118484

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

Merged

Conversation

markshannon
Copy link
Member

@markshannon markshannon commented May 1, 2024

#118286 makes the assumption that _Py_HandlePending() will clear the eval_breaker, if not on the first call, then eventually.
However, this isn't true for pending calls.

This PR makes sure that _Py_HandlePending() does eventually clear the eval_breaker.

Copy link
Member

@ericsnowcurrently ericsnowcurrently left a comment

Choose a reason for hiding this comment

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

This makes sense. I have but one key question.

Comment on lines +885 to +889
To avoid all threads constantly stopping on the eval breaker,
we clear the bit for this thread and make sure it is set
for the thread currently handling the pending call. */
_Py_set_eval_breaker_bit(pending->handling_thread, _PY_CALLS_TO_DO_BIT);
_Py_unset_eval_breaker_bit(tstate, _PY_CALLS_TO_DO_BIT);
Copy link
Member

Choose a reason for hiding this comment

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

Does this mean that only the thread that was already handling pending calls will handle any remaining ones (until the queue is empty)? Currently the next available thread handles the remaining ones, so no single thread is blocked too long handling pending calls.

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently, the next available thread keeps tripping the eval breaker until the current call is handled, so the _PY_CALLS_TO_DO_BIT is in effect blocking.

A non-blocking and fair mechanism would be good, but the current mechanism is neither.
This makes it non-blocking, although maybe less fair.

Copy link
Member

Choose a reason for hiding this comment

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

That's fine. We can circle back to a fair mechanism later, if someone cares enough.

Copy link
Member

@ericsnowcurrently ericsnowcurrently left a comment

Choose a reason for hiding this comment

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

LGTM

@markshannon markshannon merged commit 39981fd into python:main May 1, 2024
37 checks passed
@markshannon markshannon deleted the make-progress-on-pending-calls branch May 1, 2024 21:18
SonicField pushed a commit to SonicField/cpython that referenced this pull request May 8, 2024
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.

2 participants