(original) (raw)
changeset: 85871:687dd81cee3b user: Antoine Pitrou solipsis@pitrou.net date: Sun Sep 29 22🔞38 2013 +0200 files: Lib/site.py Misc/NEWS description: 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. diff -r 280d403434c4 -r 687dd81cee3b Lib/site.py --- a/Lib/site.py Sun Sep 29 15🔞43 2013 -0400 +++ b/Lib/site.py Sun Sep 29 22🔞38 2013 +0200 @@ -405,12 +405,19 @@ # 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 diff -r 280d403434c4 -r 687dd81cee3b Misc/NEWS --- a/Misc/NEWS Sun Sep 29 15🔞43 2013 -0400 +++ b/Misc/NEWS Sun Sep 29 22🔞38 2013 +0200 @@ -15,6 +15,10 @@ 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 /solipsis@pitrou.net