Skip to content

Commit e20d31c

Browse files
bpo-19891: Ignore error while writing history file (GH-8483)
(cherry picked from commit b249966) Co-authored-by: Anthony Sottile <[email protected]>
1 parent 02c4eae commit e20d31c

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
@@ -418,7 +418,16 @@ def register_readline():
418418
readline.read_history_file(history)
419419
except IOError:
420420
pass
421-
atexit.register(readline.write_history_file, history)
421+
422+
def write_history():
423+
try:
424+
readline.write_history_file(history)
425+
except (FileNotFoundError, PermissionError):
426+
# home directory does not exist or is not writable
427+
# https://bugs.python.org/issue19891
428+
pass
429+
430+
atexit.register(write_history)
422431

423432
sys.__interactivehook__ = register_readline
424433

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)