Skip to content
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

importing jedi might lower your recursion limit #1925

Open
wimglenn opened this issue Apr 10, 2023 · 3 comments
Open

importing jedi might lower your recursion limit #1925

wimglenn opened this issue Apr 10, 2023 · 3 comments
Labels

Comments

@wimglenn
Copy link

wimglenn commented Apr 10, 2023

>>> sys.setrecursionlimit(5000)
>>> sys.getrecursionlimit()
5000
>>> import jedi
>>> sys.getrecursionlimit()
3000

In https://github.com/davidhalter/jedi/blob/v0.18.2/jedi/api/__init__.py#L46-L48

# Jedi uses lots and lots of recursion. By setting this a little bit higher, we
# can remove some "maximum recursion depth" errors.
sys.setrecursionlimit(3000)

Perhaps it should check if you're not already higher than 3000, so that you're not lowering an already higher bound which user might have set for a good reason.

Actually, I think it's questionable for a library to mess with the global recursion limit in the first place - maybe the parts of jedi which need to use deep recursion can do so with a context-managed recursion limit, or be rewritten to use an explicit stack.

@davidhalter
Copy link
Owner

Actually, I think it's questionable for a library to mess with the global recursion limit in the first place - maybe the parts of jedi which need to use deep recursion can do so with a context-managed recursion limit, or be rewritten to use an explicit stack.

Completely agree. This should be a decorator. We discussed this here already
dask/dask#9805 and to a lesser degree here: #1902.

Feel free to send a pull request that sets the recusion limit in specific places and resets it afterwards.

@mezzarobba
Copy link

See sagemath/sage#35803 for an (admittedly dubious) example of this happening in the wild.

@mgorny
Copy link
Contributor

mgorny commented Dec 4, 2023

There's another side to this: 3000 may be too high in some scenarios, and may cause CPython to crash instead of throwing an exception. I've seen it multiple times now, when jedi was imported implicitly via some other package and then caused e.g. django tests to crash.

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

No branches or pull requests

4 participants