Skip to content

Document how import chains are affected by sys.setrecursionlimit #128544

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
seddonym opened this issue Jan 6, 2025 · 2 comments
Open

Document how import chains are affected by sys.setrecursionlimit #128544

seddonym opened this issue Jan 6, 2025 · 2 comments
Labels
docs Documentation in the Doc dir

Comments

@seddonym
Copy link

seddonym commented Jan 6, 2025

While working on a very large Python codebase, I ran into some undocumented behaviour.

A chain of imports (i.e. one module imports another, which imports another, which imports another) will cause a RecursionError to be raised if the Python recursion limit is not high enough. (Note, there is no recursion involved.)

Longer chains of imports can be enabled by increasing the recursion limit. But the limit has no effect beyond a certain point (around 10,000). (I believe this is due to Py_C_RECURSION_LIMIT, mentioned in by Serhiy Storchaka.)

A workaround is available: you can import the modules in a different order.

I've created a repository with more analysis and scripts to reproduce the problem. I also started a Discuss topic on the subject.

From what I understand, this is a complex problem that is unlikely to be fixed. But I think it would be helpful to document this, probably in the docs for sys.setrecursionlimit.

I would be happy to try to do a pull request, assuming the core team agree that it should be added.

@seddonym seddonym added the docs Documentation in the Doc dir label Jan 6, 2025
@seddonym seddonym changed the title Document how import chains are affected by sys.setrecursionlimit Document how import chains are affected by sys.setrecursionlimit Jan 6, 2025
@pochmann3
Copy link
Contributor

pochmann3 commented Jan 6, 2025

Import chains are just one case. It's a more general issue, also see these:

#112215

#112282

@seddonym
Copy link
Author

seddonym commented Jan 7, 2025

Thanks for linking. I've asked on that second issue whether it would make sense to fold this issue into that one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
Status: Todo
Development

No branches or pull requests

2 participants