IDLE raises an uncaught traceback when a file that is open in the editor is deleted or renamed by another program and the IDLE window is then refocused.
EditorWindow.focus_in_event runs on every <FocusIn> event and calls EditorWindow.last_mtime, which calls os.path.getmtime(self.io.filename) with no error handling. When the open file has been removed or renamed, getmtime raises FileNotFoundError, which escapes the Tk event handler and breaks the modified-on-disk reload check.
Reproduction
Open a file in the IDLE editor, delete or rename it in another program, then click back into the IDLE window. A traceback like this reaches the console and the reload check stops working:
FileNotFoundError: [Errno 2] No such file or directory: '.../somefile.py'
The same call reproduced without a GUI:
importos, tempfile, typesfromidlelib.editorimportEditorWindowwithtempfile.TemporaryDirectory() asd:
path=os.path.join(d, 'gone.py')
open(path, 'w').close()
mtime=os.path.getmtime(path)
os.remove(path)
stub=types.SimpleNamespace(io=types.SimpleNamespace(filename=path), mtime=mtime)
EditorWindow.last_mtime(stub) # raises FileNotFoundError on the main branch
Suggested fix
Guard os.path.getmtime in last_mtime with try/except OSError and return the last known mtime, so focus_in_event sees no change and does not prompt to reload a file that is gone.
I choose the IDLE Issues topic "File save" as the closest because this is not about editing but about interaction with the external filesystem. I suspect that there could also be problems if Shell or an output window have been 'saved as'.
This is worse than a traceback on FocusIn: the same last_mtime() runs from set_saved(True) inside EditorWindow.__init__, so opening a file that does not exist yet — python -m idlelib new.py, the usual way to start a new script — aborts IDLE at startup with FileNotFoundError. Regression from gh-94523; affects 3.13.15, 3.14.7, 3.15.0b1 and main.
Proposed behavior: last_mtime() returns None when there is no file or it cannot be stat'ed (not 0, which is a valid mtime on filesystems without timestamps). If a file that was there is gone on FocusIn, ask Close / Save As / Ignore (default Save As); Ignore marks the window unsaved and resets the stored mtime to None so the question is asked once. This is an approximate plan; details can be changed later. See the review on #153481.
changed the title [-]IDLE crashes when a file open in the editor is deleted or renamed externally[/-][+]IDLE fails to start or raises when an editor window's file does not exist[/+]on Sep 15, 2026
Activity
terryjreedy commented on Jul 10, 2026
I choose the IDLE Issues topic "File save" as the closest because this is not about editing but about interaction with the external filesystem. I suspect that there could also be problems if Shell or an output window have been 'saved as'.
serhiy-storchaka commented on Sep 15, 2026
This is worse than a traceback on FocusIn: the same last_mtime() runs from set_saved(True) inside EditorWindow.__init__, so opening a file that does not exist yet — python -m idlelib new.py, the usual way to start a new script — aborts IDLE at startup with FileNotFoundError. Regression from gh-94523; affects 3.13.15, 3.14.7, 3.15.0b1 and main.
Traceback: pyshell.main → filelist.open → EditorWindow.__init__ (editor.py:242) → iomenu.set_filename → set_saved → editor.set_saved (1033) → last_mtime (1121) → os.path.getmtime.
Proposed behavior: last_mtime() returns None when there is no file or it cannot be stat'ed (not 0, which is a valid mtime on filesystems without timestamps). If a file that was there is gone on FocusIn, ask Close / Save As / Ignore (default Save As); Ignore marks the window unsaved and resets the stored mtime to None so the question is asked once. This is an approximate plan; details can be changed later. See the review on #153481.
pythongh-153480: Return None from last_mtime() and handle a deleted file
pythongh-153480: Clear mtime in the deleted-file dialog before Save As
pythongh-153480: Clear mtime before the deleted-file dialog for all c…
gh-153480: Stop IDLE crashing when a file open in the editor is delet…
[3.13] gh-153480: Stop IDLE crashing when a file open in the editor i…
[3.14] gh-153480: Stop IDLE crashing when a file open in the editor i…
[3.15] gh-153480: Stop IDLE crashing when a file open in the editor i…