问题
I have a Python program that reads lines of files and analyzes them. The program intentionally reads many lines into the RAM.
The program started getting MemoryError while appending a line (as str) to list. When I check in the task manager (the program runs on Windows 10), I see that the memory of the program is on 1635MB (stable) and the total memory use of the machine is below 50%.
I read that Python does not limit the memory, so what could be the reason?
Technical details:
I use Python 3.6.5 on Windows 10, 64-bit 16GB RAM machine. I run the program from the PowerShell terminal and not through the IDE.
回答1:
I see that the memory of the program is on 1635MB
Windows EXEs compiled as 32-bit have, by default, a 2GB memory limit even when on 64-bit OS SKUs where plenty more memory is available. You're at 1.6 GB, so you're probably bumping up against this limit.
Make sure you are running the 64-bit version of Python.exe. Python.org's download page defaults to 32-bit for unknown reasons. But if you browse to the bottom of their download page for a given release, you can find the x86-64 version for 64-bit architecture.
来源:https://stackoverflow.com/questions/59440599/python-memory-error-when-memory-is-available