New submission from Josh Rosenberg:
Accidentally discovered this while running code that processes a whole bunch of
files, when it turned out the files were empty. The readline method of
fileinput.input will make a recursive call to continue processing when it
reaches the end of a file. This is fine when files aren't empty, but if you
have sufficient (~1000) empty files being processed, this causes recursion
errors.
Simple example:
>>> for i in range(10000):
... with open('test{}'.format(i), 'wb'):
... pass
...
>>> import fileinput, glob
>>> ''.join(fileinput.input(glob.glob('./test*')))
Traceback ...
... (almost all the levels are showing the self.readline() call at the end of
readline) ...
RecursionError: maximum recursion depth exceeded
Admittedly a niche case, but a relatively simple switch from recursion to
iteration would solve it. Same problem appears in all versions of Python.
----------
components: Library (Lib)
messages: 275072
nosy: josh.r
priority: normal
severity: normal
status: open
title: fileinput causes RecursionErrors when dealing with large numbers of
empty files
versions: Python 2.7, Python 3.5, Python 3.6, Python 3.7
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue28024>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com