Skip to content

Commit

Permalink
dont fail hard when readline is fucked
Browse files Browse the repository at this point in the history
  • Loading branch information
dcramer committed Jun 30, 2017
1 parent d47f9cf commit 25c721f
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions python/pythonrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@
from __future__ import print_function

import os
import readline

readline.parse_and_bind('tab: complete')
history = os.path.expanduser("~/.pythonhist")

if os.path.exists(history):
try:
readline.read_history_file(history)
except IOError:
print("Failed to read %r: %s" % (history, e))

readline.set_history_length(1024 * 5)
try:
import readline
except ImportError:
import traceback; traceback.print_exc()
history = None
else:
readline.parse_and_bind('tab: complete')
history = os.path.expanduser("~/.pythonhist")

if os.path.exists(history):
try:
readline.read_history_file(history)
except IOError:
print("Failed to read %r: %s" % (history, e))

readline.set_history_length(1024 * 5)

def write_history(history):
def wrapped():
Expand All @@ -25,4 +29,5 @@ def wrapped():
return wrapped

import atexit
atexit.register(write_history(history))
if history:
atexit.register(write_history(history))

0 comments on commit 25c721f

Please sign in to comment.