diff options
author | Ned Deily <nad@acm.org> | 2011-12-14 22:57:43 (GMT) |
---|---|---|
committer | Ned Deily <nad@acm.org> | 2011-12-14 22:57:43 (GMT) |
commit | 40ad04171d7f3773ed29a3ff13a1d58eefab57c2 (patch) | |
tree | e062135434d80c078b3b7a8e877117fffcb548f6 /Lib/idlelib/PyShell.py | |
parent | 27b154ea57dcb4232701504557e7c2cebbd5458e (diff) | |
download | cpython-40ad04171d7f3773ed29a3ff13a1d58eefab57c2.zip cpython-40ad04171d7f3773ed29a3ff13a1d58eefab57c2.tar.gz cpython-40ad04171d7f3773ed29a3ff13a1d58eefab57c2.tar.bz2 |
Issue #4625: If IDLE cannot write to its recent file or breakpoint
files, display a message popup and continue rather than crash.
(original patch by Roger Serwy)
Diffstat (limited to 'Lib/idlelib/PyShell.py')
-rw-r--r-- | Lib/idlelib/PyShell.py | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/Lib/idlelib/PyShell.py b/Lib/idlelib/PyShell.py index ce83f19..96efcec 100644 --- a/Lib/idlelib/PyShell.py +++ b/Lib/idlelib/PyShell.py @@ -207,18 +207,26 @@ class PyShellEditorWindow(EditorWindow): breaks = self.breakpoints filename = self.io.filename try: - lines = open(self.breakpointPath,"r").readlines() + with open(self.breakpointPath,"r") as old_file: + lines = old_file.readlines() except IOError: lines = [] - new_file = open(self.breakpointPath,"w") - for line in lines: - if not line.startswith(filename + '='): - new_file.write(line) - self.update_breakpoints() - breaks = self.breakpoints - if breaks: - new_file.write(filename + '=' + str(breaks) + '\n') - new_file.close() + try: + with open(self.breakpointPath,"w") as new_file: + for line in lines: + if not line.startswith(filename + '='): + new_file.write(line) + self.update_breakpoints() + breaks = self.breakpoints + if breaks: + new_file.write(filename + '=' + str(breaks) + '\n') + except IOError as err: + if not getattr(self.root, "breakpoint_error_displayed", False): + self.root.breakpoint_error_displayed = True + tkMessageBox.showerror(title='IDLE Error', + message='Unable to update breakpoint list:\n%s' + % str(err), + parent=self.text) def restore_file_breaks(self): self.text.update() # this enables setting "BREAK" tags to be visible |