Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fileinput causes RecursionErrors when dealing with large numbers of empty files #72211

Closed
MojoVampire mannequin opened this issue Sep 8, 2016 · 2 comments
Closed

fileinput causes RecursionErrors when dealing with large numbers of empty files #72211

MojoVampire mannequin opened this issue Sep 8, 2016 · 2 comments
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir

Comments

@MojoVampire
Copy link
Mannequin

MojoVampire mannequin commented Sep 8, 2016

BPO 28024
Nosy @serhiy-storchaka, @MojoVampire

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2016-09-13.00:12:44.319>
created_at = <Date 2016-09-08.17:30:58.793>
labels = ['3.7', 'library']
title = 'fileinput causes RecursionErrors when dealing with large numbers of empty files'
updated_at = <Date 2016-09-13.00:12:44.319>
user = 'https://github.com/MojoVampire'

bugs.python.org fields:

activity = <Date 2016-09-13.00:12:44.319>
actor = 'berker.peksag'
assignee = 'none'
closed = True
closed_date = <Date 2016-09-13.00:12:44.319>
closer = 'berker.peksag'
components = ['Library (Lib)']
creation = <Date 2016-09-08.17:30:58.793>
creator = 'josh.r'
dependencies = []
files = []
hgrepos = []
issue_num = 28024
keywords = []
message_count = 2.0
messages = ['275072', '276135']
nosy_count = 3.0
nosy_names = ['duaneg', 'serhiy.storchaka', 'josh.r']
pr_nums = []
priority = 'normal'
resolution = 'out of date'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue28024'
versions = ['Python 2.7', 'Python 3.5', 'Python 3.6', 'Python 3.7']

@MojoVampire
Copy link
Mannequin Author

MojoVampire mannequin commented Sep 8, 2016

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.

@MojoVampire MojoVampire mannequin added 3.7 (EOL) end of life stdlib Python modules in the Lib dir labels Sep 8, 2016
@duaneg
Copy link
Mannequin

duaneg mannequin commented Sep 12, 2016

This was fixed in 2.7, 3.5 and head when bpo-15068 was fixed.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir
Projects
None yet
Development

No branches or pull requests

1 participant