Skip to content

Commit 3182d08

Browse files
committed
Don't lose the session history if an EnvironmentError occurs.
Patch by Sebastian Ramacher. Closes issue #183.
1 parent 2f0a6ba commit 3182d08

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

bpython/repl.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,7 @@ def push(self, s, insert_into_history=True):
748748
if insert_into_history:
749749
if self.config.hist_length:
750750
histfilename = os.path.expanduser(self.config.hist_file)
751+
oldhistory = self.rl_history.entries
751752
self.rl_history.entries = []
752753
if os.path.exists(histfilename):
753754
self.rl_history.load(histfilename, getpreferredencoding())
@@ -756,6 +757,8 @@ def push(self, s, insert_into_history=True):
756757
self.rl_history.save(histfilename, getpreferredencoding(), self.config.hist_length)
757758
except EnvironmentError, err:
758759
self.interact.notify("Error occured while writing to file %s (%s) " % (histfilename, err.strerror))
760+
self.rl_history.entries = oldhistory
761+
self.rl_history.append(s)
759762
else:
760763
self.rl_history.append(s)
761764

0 commit comments

Comments
 (0)