]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-19891: Ignore error while writing history file (GH-8483)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 6 Aug 2018 09:15:42 +0000 (02:15 -0700)
committerGitHub <noreply@github.com>
Mon, 6 Aug 2018 09:15:42 +0000 (02:15 -0700)
(cherry picked from commit b2499669ef2e6dc9a2cdb49b4dc498e078167e26)

Co-authored-by: Anthony Sottile <asottile@umich.edu>
Lib/site.py
Misc/NEWS.d/next/Library/2018-07-26-08-45-49.bpo-19891.Y-3IiB.rst [new file with mode: 0644]

index 1bd63ccf6a23537594b5fed1b67309913a862fae..86ca2dba61bf3c729eadd4c90bb0b664ae0b4dbd 100644 (file)
@@ -418,7 +418,16 @@ def enablerlcompleter():
                 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
 
diff --git a/Misc/NEWS.d/next/Library/2018-07-26-08-45-49.bpo-19891.Y-3IiB.rst b/Misc/NEWS.d/next/Library/2018-07-26-08-45-49.bpo-19891.Y-3IiB.rst
new file mode 100644 (file)
index 0000000..18e10f5
--- /dev/null
@@ -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.