summaryrefslogtreecommitdiffstats
path: root/Tools/scripts/find_recursionlimit.py
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/scripts/find_recursionlimit.py')
-rwxr-xr-xTools/scripts/find_recursionlimit.py46
1 files changed, 25 insertions, 21 deletions
diff --git a/Tools/scripts/find_recursionlimit.py b/Tools/scripts/find_recursionlimit.py
index 88e9bb5..7a86603 100755
--- a/Tools/scripts/find_recursionlimit.py
+++ b/Tools/scripts/find_recursionlimit.py
@@ -1,4 +1,4 @@
-#! /usr/bin/env python
+#! /usr/bin/env python3
"""Find the maximum recursion limit that prevents interpreter termination.
This script finds the maximum safe recursion limit on a particular
@@ -71,28 +71,30 @@ def test_recurse():
return test_recurse()
def test_cpickle(_cache={}):
+ import io
try:
- import cPickle
+ import _pickle
except ImportError:
- print "cannot import cPickle, skipped!"
+ print("cannot import _pickle, skipped!")
return
- l = None
+ k, l = None, None
for n in itertools.count():
try:
l = _cache[n]
continue # Already tried and it works, let's save some time
except KeyError:
for i in range(100):
- l = [l]
- cPickle.dumps(l, protocol=-1)
+ l = [k, l]
+ k = {i: l}
+ _pickle.Pickler(io.BytesIO(), protocol=-1).dump(l)
_cache[n] = l
def check_limit(n, test_func_name):
sys.setrecursionlimit(n)
if test_func_name.startswith("test_"):
- print test_func_name[5:]
+ print(test_func_name[5:])
else:
- print test_func_name
+ print(test_func_name)
test_func = globals()[test_func_name]
try:
test_func()
@@ -102,16 +104,18 @@ def check_limit(n, test_func_name):
except (RuntimeError, AttributeError):
pass
else:
- print "Yikes!"
-
-limit = 1000
-while 1:
- check_limit(limit, "test_recurse")
- check_limit(limit, "test_add")
- check_limit(limit, "test_repr")
- check_limit(limit, "test_init")
- check_limit(limit, "test_getattr")
- check_limit(limit, "test_getitem")
- check_limit(limit, "test_cpickle")
- print "Limit of %d is fine" % limit
- limit = limit + 100
+ print("Yikes!")
+
+if __name__ == '__main__':
+
+ limit = 1000
+ while 1:
+ check_limit(limit, "test_recurse")
+ check_limit(limit, "test_add")
+ check_limit(limit, "test_repr")
+ check_limit(limit, "test_init")
+ check_limit(limit, "test_getattr")
+ check_limit(limit, "test_getitem")
+ check_limit(limit, "test_cpickle")
+ print("Limit of %d is fine" % limit)
+ limit = limit + 100