mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Issue #3850: Misc/find_recursionlimit.py was broken.
Reviewed by A.M. Kuchling.
This commit is contained in:
parent
d51e07f989
commit
3c9f541ef8
2 changed files with 27 additions and 8 deletions
|
@ -1,22 +1,30 @@
|
|||
#! /usr/bin/env python
|
||||
"""Find the maximum recursion limit that prevents core dumps
|
||||
"""Find the maximum recursion limit that prevents interpreter termination.
|
||||
|
||||
This script finds the maximum safe recursion limit on a particular
|
||||
platform. If you need to change the recursion limit on your system,
|
||||
this script will tell you a safe upper bound. To use the new limit,
|
||||
call sys.setrecursionlimit.
|
||||
call sys.setrecursionlimit().
|
||||
|
||||
This module implements several ways to create infinite recursion in
|
||||
Python. Different implementations end up pushing different numbers of
|
||||
C stack frames, depending on how many calls through Python's abstract
|
||||
C API occur.
|
||||
|
||||
After each round of tests, it prints a message
|
||||
Limit of NNNN is fine.
|
||||
After each round of tests, it prints a message:
|
||||
"Limit of NNNN is fine".
|
||||
|
||||
It ends when Python causes a segmentation fault because the limit is
|
||||
too high. On platforms like Mac and Windows, it should exit with a
|
||||
MemoryError.
|
||||
The highest printed value of "NNNN" is therefore the highest potentially
|
||||
safe limit for your system (which depends on the OS, architecture, but also
|
||||
the compilation flags). Please note that it is practically impossible to
|
||||
test all possible recursion paths in the interpreter, so the results of
|
||||
this test should not be trusted blindly -- although they give a good hint
|
||||
of which values are reasonable.
|
||||
|
||||
NOTE: When the C stack space allocated by your system is exceeded due
|
||||
to excessive recursion, exact behaviour depends on the platform, although
|
||||
the interpreter will always fail in a likely brutal way: either a
|
||||
segmentation fault, a MemoryError, or just a silent abort.
|
||||
|
||||
NB: A program that does not use __methods__ can set a higher limit.
|
||||
"""
|
||||
|
@ -88,7 +96,10 @@ def check_limit(n, test_func_name):
|
|||
test_func = globals()[test_func_name]
|
||||
try:
|
||||
test_func()
|
||||
except RuntimeError:
|
||||
# AttributeError can be raised because of the way e.g. PyDict_GetItem()
|
||||
# silences all exceptions and returns NULL, which is usually interpreted
|
||||
# as "missing attribute".
|
||||
except (RuntimeError, AttributeError):
|
||||
pass
|
||||
else:
|
||||
print "Yikes!"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue