Skip to content

Commit b249966

Browse files
asottilemethane
authored andcommitted
bpo-19891: Ignore error while writing history file (GH-8483)
1 parent 336c945 commit b249966

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Lib/site.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,16 @@ def register_readline():
439439
readline.read_history_file(history)
440440
except OSError:
441441
pass
442-
atexit.register(readline.write_history_file, history)
442+
443+
def write_history():
444+
try:
445+
readline.write_history_file(history)
446+
except (FileNotFoundError, PermissionError):
447+
# home directory does not exist or is not writable
448+
# https://bugs.python.org/issue19891
449+
pass
450+
451+
atexit.register(write_history)
443452

444453
sys.__interactivehook__ = register_readline
445454

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Ignore errors caused by missing / non-writable homedir while writing history
2+
during exit of an interactive session. Patch by Anthony Sottile.

0 commit comments

Comments
 (0)