Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
7c018aa3
Commit
7c018aa3
authored
Jan 11, 2016
by
Ezio Melotti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#25991: fix readline example to limit history size. Patch by Daniel Dye.
parent
e9736204
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
0 deletions
+4
-0
Doc/library/readline.rst
Doc/library/readline.rst
+4
-0
No files found.
Doc/library/readline.rst
View file @
7c018aa3
...
...
@@ -209,6 +209,8 @@ from the user's :envvar:`PYTHONSTARTUP` file. ::
histfile = os.path.join(os.path.expanduser("~"), ".python_history")
try:
readline.read_history_file(histfile)
# default history len is -1 (infinite), which may grow unruly
readline.set_history_length(1000)
except FileNotFoundError:
pass
...
...
@@ -234,6 +236,7 @@ sessions, by only appending the new history. ::
def save(prev_h_len, histfile):
new_h_len = readline.get_history_length()
readline.set_history_length(1000)
readline.append_history_file(new_h_len - prev_h_len, histfile)
atexit.register(save, h_len, histfile)
...
...
@@ -261,4 +264,5 @@ support history save/restore. ::
atexit.register(self.save_history, histfile)
def save_history(self, histfile):
readline.set_history_length(1000)
readline.write_history_file(histfile)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment