classification
Title: readline example eventually consumes all memory
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.6, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Daniel Dye, dangyogi, docs@python, ezio.melotti, martin.panter, python-dev
Priority: normal Keywords: easy, patch

Created on 2016-01-02 04:28 by dangyogi, last changed 2016-01-12 02:02 by martin.panter. This issue is now closed.

Files
File name Uploaded Description Edit
doc_library_readline.patch Daniel Dye, 2016-01-09 09:47 Patch the Doc/library/readline.rst file review
Messages (6)
msg257325 - (view) Author: Bruce Frederiksen (dangyogi) Date: 2016-01-02 04:28
The Example in the readline documentation (section 6.7 of the Library Reference) shows how to save your readline history in a file, and restore it each time you start Python.

The problem with the Example is that it does not include a call to readline.set_history_length and the default is -1 (infinite).

As a Python developer, I start Python quite a lot and had a .python_history file that was 850M bytes.  Just starting Python was causing my system to thrash before the first prompt (>>>) even appeared.

I suggest adding the following line to the example to avoid this:

readline.set_history_length(1000)

I'm not sure how far back this goes in terms of earlier versions of Python, but probably quite far.
msg257778 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-01-08 21:03
What version of Readline are you using? Is it perhaps Editline (libedit)? When I experimented with Editline on Linux once, I think I saw the history file doubling in size every time I ran Python. Maybe that is what you are seeing.
msg257813 - (view) Author: Daniel Dye (Daniel Dye) Date: 2016-01-09 09:47
Add a history length of 1000 lines
Default is -1 (infinite), which may grow unruly
msg258020 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-01-11 21:31
New changeset 9a2c891a4333 by Ezio Melotti in branch '2.7':
#25991: fix readline example to limit history size.  Patch by Daniel Dye.
https://hg.python.org/cpython/rev/9a2c891a4333

New changeset 416db1a2fb81 by Ezio Melotti in branch '3.5':
#25991: fix readline example to limit history size.  Patch by Daniel Dye.
https://hg.python.org/cpython/rev/416db1a2fb81

New changeset cb08e5271cc0 by Ezio Melotti in branch 'default':
#25991: merge with 3.5.
https://hg.python.org/cpython/rev/cb08e5271cc0
msg258021 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2016-01-11 21:32
Fixed, thanks for the patch!
msg258053 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-01-12 02:02
Thanks Ezio for handling this. Ignore my previous comment; I missed the key word “example” :)
History
Date User Action Args
2016-01-12 02:02:18martin.pantersetmessages: + msg258053
2016-01-11 21:32:45ezio.melottisetstatus: open -> closed
resolution: fixed
messages: + msg258021

stage: needs patch -> resolved
2016-01-11 21:31:51python-devsetnosy: + python-dev
messages: + msg258020
2016-01-09 09:47:48Daniel Dyesetfiles: + doc_library_readline.patch

nosy: + Daniel Dye
messages: + msg257813

keywords: + patch
2016-01-08 21:03:51martin.pantersetnosy: + martin.panter
messages: + msg257778
2016-01-08 17:50:19ezio.melottisetversions: + Python 2.7, Python 3.5, Python 3.6, - Python 3.4
nosy: + ezio.melotti

keywords: + easy
type: resource usage -> enhancement
stage: needs patch
2016-01-02 04:28:53dangyogicreate