Skip to content

Commit 22bb4da

Browse files
committed
Do not use system recursion limit from the time of import.
1 parent b2acb67 commit 22bb4da

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

compileall2.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343
pyc_header_lenght = 8
4444
pyc_header_format = (pyc_struct_format, importlib.util.MAGIC_NUMBER)
4545

46-
RECURSION_LIMIT = sys.getrecursionlimit()
47-
4846
__all__ = ["compile_dir","compile_file","compile_path"]
4947

5048
def optimization_kwarg(opt):
@@ -60,7 +58,7 @@ def optimization_kwarg(opt):
6058
else:
6159
return dict()
6260

63-
def _walk_dir(dir, maxlevels=RECURSION_LIMIT, quiet=0):
61+
def _walk_dir(dir, maxlevels, quiet=0):
6462
if PY36 and quiet < 2 and isinstance(dir, os.PathLike):
6563
dir = os.fspath(dir)
6664
else:
@@ -85,7 +83,7 @@ def _walk_dir(dir, maxlevels=RECURSION_LIMIT, quiet=0):
8583
yield from _walk_dir(fullname, maxlevels=maxlevels - 1,
8684
quiet=quiet)
8785

88-
def compile_dir(dir, maxlevels=RECURSION_LIMIT, ddir=None, force=False,
86+
def compile_dir(dir, maxlevels=None, ddir=None, force=False,
8987
rx=None, quiet=0, legacy=False, optimize=-1, workers=1,
9088
invalidation_mode=None, stripdir=None,
9189
prependdir=None, limit_sl_dest=None):
@@ -123,6 +121,8 @@ def compile_dir(dir, maxlevels=RECURSION_LIMIT, ddir=None, force=False,
123121
from concurrent.futures import ProcessPoolExecutor
124122
except ImportError:
125123
workers = 1
124+
if maxlevels is None:
125+
maxlevels = sys.getrecursionlimit()
126126
files = _walk_dir(dir, quiet=quiet, maxlevels=maxlevels)
127127
success = True
128128
if workers is not None and workers != 1 and ProcessPoolExecutor is not None:
@@ -327,7 +327,7 @@ def main():
327327
parser = argparse.ArgumentParser(
328328
description='Utilities to support installing Python libraries.')
329329
parser.add_argument('-l', action='store_const', const=0,
330-
default=RECURSION_LIMIT, dest='maxlevels',
330+
default=None, dest='maxlevels',
331331
help="don't recurse into subdirectories")
332332
parser.add_argument('-r', type=int, dest='recursion',
333333
help=('control the maximum recursion level. '

0 commit comments

Comments
 (0)