]> granicus.if.org Git - python/commitdiff
bpo-19891: Ignore error while writing history file (GH-8483)
authorAnthony Sottile <asottile@umich.edu>
Mon, 6 Aug 2018 08:28:19 +0000 (01:28 -0700)
committerINADA Naoki <methane@users.noreply.github.com>
Mon, 6 Aug 2018 08:28:19 +0000 (17:28 +0900)
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 4595244e2f5a78ea3ef0b651e3885d1188862f09..ffd132b389e1b879df8ff7e8185508988de7c828 100644 (file)
@@ -439,7 +439,16 @@ def enablerlcompleter():
                 readline.read_history_file(history)
             except OSError:
                 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.