Reputation: 4218
When I run the python 2.7 interactive shell (in Ubuntu 12.04 LTS) I get what appears to be a memory leak. When I launch an interactive shell, the memory usage steps up at a fairly even rate until all the ram (3.9gb) is used, then it knocks back to 80% (ish) and swap space jumps up by ~200-400mb and it levels off and offers the prompt, but any further interaction pushes the RAM usage back to 100% where it stays (rendering the system pretty much inoperable).
The interactive shell can be launched from a gnome terminal, or when ssh'd into the computer from another box (I was testing using connectbot for android), and the same problem occurs.
EDIT: I removed my .pythonrc.py file and the problem seems to have disappeared. I did not change it recently (I created it a month ago and haven't touched it since, this problem started yesterday).
Here is my pythonrc file (.pythonrc.py
)
import atexit
import os
import readline
import rlcompleter
history = os.path.expanduser('~/.python_history')
readline.read_history_file(history)
readline.parse_and_bind('tab: complete')
atexit.register(readline.write_history_file, history)
EDIT 2:
I deleted my .python_history
file and that seems to have fixed the problem. The file was 1914155 lines and around 54mb. I intend to adjust my .pythonrc file so that it will only store a history of a couple hundred lines.
Upvotes: 2
Views: 474
Reputation: 4218
To fix the problem (hopefully a permanent solution), I added the following line to the .pythonrc.py
file.
import atexit
import os
import readline
import rlcompleter
history = os.path.expanduser('~/.python_history')
readline.read_history_file(history)
readline.parse_and_bind('tab: complete')
# The added line
readline.set_history_length(200)
atexit.register(readline.write_history_file, history)
I assume that any sufficiently not stupidly large number will be fine (instead of just 200), but I figure that if I am going more than 200 lines back in my history I am doing something wrong.
Upvotes: 3