Repository navigation
How can I reduce memory consumption when processing millions of records in Python? #15740
Unanswered
codehaven175
asked this question in
Q&A
Replies: 2 comments
|
let's keep in touch via discord |
0 replies
|
Hard to be specific without knowing the data format or what you're computing.... don't load all the records at once (stream them with a generator or read in chunks), and keep only small running results in memory. with open("data.txt") as f:
total = sum(len(line) for line in f) # one line in memory at a timememory then stays flat no matter how many records there are, see: https://docs.python.org/3/howto/functional.html#generators |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
?what is your answer?
All reactions