-
Notifications
You must be signed in to change notification settings - Fork 6.9k
[core] Fix python 3.12 asyncio RecursionError leading to objects_valid check #57253
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
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -679,29 +679,63 @@ def compute_task_id(ObjectRef object_ref): | |
|
|
||
|
|
||
| cdef increase_recursion_limit(): | ||
| """Double the recusion limit if current depth is close to the limit""" | ||
| """ | ||
| Ray does some weird things with asio fibers and asyncio to run asyncio actors. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Killing boost fiber is on the @edoakes's wishlist
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ya ik I talked to him about it, he said he's gonna try prioritizing next quarter 👀 |
||
| This results in the Python interpreter thinking there's a lot of recursion depth, | ||
| so we need to increase the limit when we start getting close. | ||
|
|
||
| 0x30C0000 is Python 3.12 | ||
dayshah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| On 3.12, when recursion depth increases, c_recursion_remaining will decrease, | ||
| and that's what's actually compared to raise a RecursionError. So increasing | ||
| it by 1000 when it drops below 1000 will keep us from raising the RecursionError. | ||
| https://github.com/python/cpython/blob/bfb9e2f4a4e690099ec2ec53c08b90f4d64fde36/Python/pystate.c#L1353 | ||
| 0x30B00A4 is Python 3.11 | ||
| On 3.11, the recursion depth can be calculated with recursion_limit - recursion_remaining. | ||
| We can get the current limit with Py_GetRecursionLimit and set it with Py_SetRecursionLimit. | ||
| We'll double the limit when there's less than 500 remaining. | ||
| On older versions | ||
| There's simply a recursion_depth variable and we'll increase the max the same | ||
| way we do for 3.11. | ||
| """ | ||
| cdef: | ||
| CPyThreadState * s = <CPyThreadState *> PyThreadState_Get() | ||
| int current_limit = Py_GetRecursionLimit() | ||
| int new_limit = current_limit * 2 | ||
| cdef extern from *: | ||
| """ | ||
| #if PY_VERSION_HEX >= 0x30C0000 | ||
| #define CURRENT_DEPTH(x) ((x)->py_recursion_limit - (x)->py_recursion_remaining) | ||
| bool IncreaseRecursionLimitIfNeeded(PyThreadState *x) { | ||
| if (x->c_recursion_remaining < 1000) { | ||
| x->c_recursion_remaining += 1000; | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| #elif PY_VERSION_HEX >= 0x30B00A4 | ||
| #define CURRENT_DEPTH(x) ((x)->recursion_limit - (x)->recursion_remaining) | ||
| bool IncreaseRecursionLimitIfNeeded(PyThreadState *x) { | ||
| int current_limit = Py_GetRecursionLimit(); | ||
| int current_depth = x->recursion_limit - x->recursion_remaining; | ||
| if (current_limit - current_depth < 500) { | ||
| Py_SetRecursionLimit(current_limit * 2); | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
edoakes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #else | ||
| #define CURRENT_DEPTH(x) ((x)->recursion_depth) | ||
| bool IncreaseRecursionLimitIfNeeded(PyThreadState *x) { | ||
| int current_limit = Py_GetRecursionLimit(); | ||
| if (current_limit - x->recursion_depth < 500) { | ||
| Py_SetRecursionLimit(current_limit * 2); | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| #endif | ||
| """ | ||
| int CURRENT_DEPTH(CPyThreadState *x) | ||
|
|
||
| int current_depth = CURRENT_DEPTH(s) | ||
| if current_limit - current_depth < 500: | ||
| Py_SetRecursionLimit(new_limit) | ||
| logger.debug("Increasing Python recursion limit to {} " | ||
| "current recursion depth is {}.".format( | ||
| new_limit, current_depth)) | ||
| c_bool IncreaseRecursionLimitIfNeeded(CPyThreadState *x) | ||
|
|
||
| CPyThreadState * s = <CPyThreadState *> PyThreadState_Get() | ||
| c_bool increased_recursion_limit = IncreaseRecursionLimitIfNeeded(s) | ||
|
|
||
| if increased_recursion_limit: | ||
| logger.debug("Increased Python recursion limit") | ||
|
|
||
|
|
||
| cdef CObjectLocationPtrToDict(CObjectLocation* c_object_location): | ||
|
|
||
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.
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 field exists in all Python versions?
Uh oh!
There was an error while loading. Please reload this page.
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 it doesn't but having it here doesn't cause any issues even if used with old python versions
recursion_limitandrecursion_remainingalso don't exist for all python versionsThere 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.
oh, interesting