File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -209,6 +209,8 @@ from the user's :envvar:`PYTHONSTARTUP` file. ::
209209 histfile = os.path.join(os.path.expanduser("~"), ".python_history")
210210 try:
211211 readline.read_history_file(histfile)
212+ # default history len is -1 (infinite), which may grow unruly
213+ readline.set_history_length(1000)
212214 except FileNotFoundError:
213215 pass
214216
@@ -234,6 +236,7 @@ sessions, by only appending the new history. ::
234236
235237 def save(prev_h_len, histfile):
236238 new_h_len = readline.get_history_length()
239+ readline.set_history_length(1000)
237240 readline.append_history_file(new_h_len - prev_h_len, histfile)
238241 atexit.register(save, h_len, histfile)
239242
@@ -261,4 +264,5 @@ support history save/restore. ::
261264 atexit.register(self.save_history, histfile)
262265
263266 def save_history(self, histfile):
267+ readline.set_history_length(1000)
264268 readline.write_history_file(histfile)
You can’t perform that action at this time.
0 commit comments