Document how import chains are affected by `sys.setrecursionlimit`
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 77.2k
- Forks
- 35.9k
- Métriques de merge des PR
- Métriques de PR en attente
Description
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.
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par la documentation de sys.setrecursionlimit et utilisez le dépôt lié import-recursion-demo ainsi que ses scripts de reproduction pour vérifier le comportement. Le travail est considéré comme terminé lorsque sont documentés la longueur que doivent atteindre les chaînes d’importation pour déclencher RecursionError, la limite supérieure approximative et la solution de contournement utilisant un autre ordre d’importation.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- documentation
- Type d'issue
- Documentation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Activité
- À l'abandon
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 58/100