summaryrefslogtreecommitdiffstats
path: root/Lib/site.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2013-09-29 20:18:38 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2013-09-29 20:18:38 (GMT)
commit5d23e6d54352db7c64d152dbabef798340127ccb (patch)
tree014cb6e1ea26a7c9f25e565874c7b3b41ed1b54a /Lib/site.py
parent95536b8405e318457ea41f8f10ee645231b48faa (diff)
downloadcpython-5d23e6d54352db7c64d152dbabef798340127ccb.zip
cpython-5d23e6d54352db7c64d152dbabef798340127ccb.tar.gz
cpython-5d23e6d54352db7c64d152dbabef798340127ccb.tar.bz2
Issue #5845: In site.py, only load readline history from ~/.python_history if no history has been read already. This avoids double writes to the history file at shutdown.
Diffstat (limited to 'Lib/site.py')
-rw-r--r--Lib/site.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/Lib/site.py b/Lib/site.py
index 9f935a3..e1fa30e 100644
--- a/Lib/site.py
+++ b/Lib/site.py
@@ -405,12 +405,19 @@ def enablerlcompleter():
# want to ignore the exception.
pass
- history = os.path.join(os.path.expanduser('~'), '.python_history')
- try:
- readline.read_history_file(history)
- except IOError:
- pass
- atexit.register(readline.write_history_file, history)
+ if readline.get_history_item(1) is None:
+ # If no history was loaded, default to .python_history.
+ # The guard is necessary to avoid doubling history size at
+ # each interpreter exit when readline was already configured
+ # through a PYTHONSTARTUP hook, see:
+ # http://bugs.python.org/issue5845#msg198636
+ history = os.path.join(os.path.expanduser('~'),
+ '.python_history')
+ try:
+ readline.read_history_file(history)
+ except IOError:
+ pass
+ atexit.register(readline.write_history_file, history)
sys.__interactivehook__ = register_readline