-
-
Notifications
You must be signed in to change notification settings - Fork 448
MemoryError in coverage report
on Python 3.12
#1785
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
Comments
Confirmed: it didn't raise a |
This can be reproduced by converting the large dict to a string, then running: import io, tokenize
import largedict
text = largedict.d # The large dict as a string
readline = io.StringIO(text).readline
list(tokenize.generate_tokens(readline)) The excessive memory usage comes from the huge list that is created here: coveragepy/coverage/phystokens.py Line 179 in 81089de
Given that the list is only used to iterate tokens, it might be better to simply return |
Hmm, I don't get it. You say:
But reformatting the file to be on multiple lines makes it work fine, with a list of 450050 tokens. So it's not just the number of tokens, there's something about the one-line that is the problem, and it's internal to tokenize? |
You're right, I confirmed that removing the list from coverage would reduce the memory usage, but didn't think it through. When calling |
Looks like python/cpython#119118 is narrowing down to a fix, so I'll close this. |
Describe the bug
On Python 3.12 an error occurs in
coverage report
, lower Python versions seem to be fine:CI logs: https://github.com/cvzi/coverage_large_dict/actions/runs/9125997761/job/25093333034
To Reproduce
Python 3.12 on Windows and Ubuntu
coverage.py 7.5.1 with C extension
coverage debug sys
What versions of what packages do you have installed? Only coverage and pytest 8.2.0
What code shows the problem? I suspect it's the large dictionary as a literal in a single line that causes the problem. Something like this:
See this 3 MB file: https://github.com/cvzi/coverage_large_dict/blob/main/largedict/__init__.py
What commands should we run to reproduce the problem?
This repository is a minimal example: https://github.com/cvzi/coverage_large_dict
Additional context
When the same large dictionary is formated in a pretty way with newlines and spaces, the problem doesn't occur
The text was updated successfully, but these errors were encountered: