diff --git a/Lib/site.py b/Lib/site.py --- 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