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

(cherry picked from commit b2499669ef2e6dc9a2cdb49b4dc498e078167e26)

Co-authored-by: Anthony Sottile <asottile@umich.edu>
diff --git a/Lib/site.py b/Lib/site.py
index 4595244..ffd132b 100644
--- a/Lib/site.py
+++ b/Lib/site.py
@@ -439,7 +439,16 @@
                 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