Commit 167c3367 authored by Ezio Melotti's avatar Ezio Melotti

#25991: fix readline example to limit history size. Patch by Daniel Dye.

parent 8da4023e
...@@ -214,6 +214,8 @@ normally be executed automatically during interactive sessions from the user's ...@@ -214,6 +214,8 @@ normally be executed automatically during interactive sessions from the user's
histfile = os.path.join(os.path.expanduser("~"), ".pyhist") histfile = os.path.join(os.path.expanduser("~"), ".pyhist")
try: try:
readline.read_history_file(histfile) readline.read_history_file(histfile)
# default history len is -1 (infinite), which may grow unruly
readline.set_history_length(1000)
except IOError: except IOError:
pass pass
import atexit import atexit
...@@ -244,5 +246,6 @@ support history save/restore. :: ...@@ -244,5 +246,6 @@ support history save/restore. ::
atexit.register(self.save_history, histfile) atexit.register(self.save_history, histfile)
def save_history(self, histfile): def save_history(self, histfile):
readline.set_history_length(1000)
readline.write_history_file(histfile) readline.write_history_file(histfile)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment