GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — IDLE fails to start or raises when an editor window's file does not exist · Issue #153480 · python/cpython

IDLE fails to start or raises when an editor window's file does not exist #153480

New issue
Copy link
New issue
Copy link
Closed
Closed
IDLE fails to start or raises when an editor window's file does not exist#153480
Copy link
Labels
3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-IDLEtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or errortype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump

Description

@tonghuaroot
tonghuaroot
opened on Jul 10, 2026
Issue body actions

Bug report

Bug description:

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:

import os, tempfile, types
from idlelib.editor import EditorWindow

with tempfile.TemporaryDirectory() as d:
    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.

CPython versions tested on:

3.16, CPython main branch

Operating systems tested on:

macOS

Linked PRs

  • gh-153480: Stop IDLE crashing when a file open in the editor is deleted #153481
  • [3.14] gh-153480: Stop IDLE crashing when a file open in the editor is deleted (GH-153481) #158262
  • [3.13] gh-153480: Stop IDLE crashing when a file open in the editor is deleted (GH-153481) #158263
  • [3.15] gh-153480: Stop IDLE crashing when a file open in the editor is deleted (GH-153481) #158264

Activity

  1. tonghuaroot
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Jul 10, 2026
  2. StanFromIreland
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    topic-IDLE
    on Jul 10, 2026
  3. StanFromIreland
    added this to IDLE Issueson Jul 10, 2026
  4. terryjreedy commented on Jul 10, 2026

    @terryjreedy
    terryjreedy
    on Jul 10, 2026
    Member
    More actions

    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'.

    Reacted by tonghuaroot (童话)
  5. terryjreedy
    added
    type-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
    on Aug 7, 2026
  6. terryjreedy
    moved this to In Progress in IDLE Issueson Aug 7, 2026
  7. serhiy-storchaka commented on Sep 15, 2026

    @serhiy-storchaka
    serhiy-storchaka
    on Sep 15, 2026
    Member
    More actions

    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.

  8. serhiy-storchaka
    added
    3.13only security fixesonly security fixes
    on Sep 15, 2026
  9. serhiy-storchaka
    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
  10. serhiy-storchaka
    added
    3.14bugs and security fixesbugs and security fixes
    3.15bugs and security fixesbugs and security fixes
    on Sep 15, 2026
  11. tonghuaroot
    added 3 commits that reference this issue on Sep 17, 2026

    pythongh-153480: Return None from last_mtime() and handle a deleted file

    a57c59b

    pythongh-153480: Clear mtime in the deleted-file dialog before Save As

    ceffab2

    pythongh-153480: Clear mtime before the deleted-file dialog for all c…

    9cabce6
  12. terryjreedy
    added 3 commits that reference this issue on Sep 27, 2026

    gh-153480: Stop IDLE crashing when a file open in the editor is delet…

    6af40a6

    [3.13] gh-153480: Stop IDLE crashing when a file open in the editor i…

    694e737

    [3.14] gh-153480: Stop IDLE crashing when a file open in the editor i…

    cbc7753
  13. terryjreedy
    closed this as completedon Sep 27, 2026
  14. terryjreedy
    added a commit that references this issue on Oct 9, 2026

    [3.15] gh-153480: Stop IDLE crashing when a file open in the editor i…

    251e132
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-IDLEtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or errortype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump

    Projects

    • IDLE Issues
      Status
      Done
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.