]> granicus.if.org Git - python/commitdiff
Issue #5845: In site.py, only load readline history from ~/.python_history if no...
authorAntoine Pitrou <solipsis@pitrou.net>
Sun, 29 Sep 2013 20:18:38 +0000 (22:18 +0200)
committerAntoine Pitrou <solipsis@pitrou.net>
Sun, 29 Sep 2013 20:18:38 +0000 (22:18 +0200)
Lib/site.py
Misc/NEWS

index 9f935a3c7e675d835c58c78c09d95cde43a71112..e1fa30eacdf626184a358fdf2788bfa10233e5b4 100644 (file)
@@ -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
 
index 8974c4b89fac841460f894b17a160453f4171531..8e28b017aab0cf13e832f3a5ab60b6aa4000e10d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -15,6 +15,10 @@ Core and Builtins
 Library
 -------
 
+- 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.
+
 - Properly initialize all fields of a SSL object after allocation.
 
 - Issue #19095: SSLSocket.getpeercert() now raises ValueError when the