bpo-19891: Ignore error while writing history file (GH-8483)

(cherry picked from commit b2499669ef)

Co-authored-by: Anthony Sottile <asottile@umich.edu>
This commit is contained in:
Miss Islington (bot) 2018-08-06 02:15:42 -07:00 committed by GitHub
parent 02c4eae35c
commit e20d31cdb3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View file

@ -418,7 +418,16 @@ def register_readline():
readline.read_history_file(history)
except IOError:
pass
atexit.register(readline.write_history_file, history)
def write_history():
try:
readline.write_history_file(history)
except (FileNotFoundError, PermissionError):
# home directory does not exist or is not writable
# https://bugs.python.org/issue19891
pass
atexit.register(write_history)
sys.__interactivehook__ = register_readline

View file

@ -0,0 +1,2 @@
Ignore errors caused by missing / non-writable homedir while writing history
during exit of an interactive session. Patch by Anthony Sottile.