Title: IDLE's close fails when io.filename set to None
Type: Stage:
Components: IDLE, macOS Versions: Python 3.8, Python 3.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: ned.deily, rhettinger, ronaldoussoren, serhiy.storchaka, terry.reedy
Priority: normal Keywords:

Created on 2018-12-02 18:30 by rhettinger, last changed 2018-12-11 21:09 by terry.reedy.

Messages (2)
msg330894 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2018-12-02 18:30
I'm not sure that sequence of events that causes this, but more than once I've gotten the following traceback.

Exception in Tkinter callback
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter/", line 1705, in __call__
    return self.func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/idlelib/", line 176, in handler
    r = l[i](event)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/idlelib/", line 54, in close_all_callback
    reply = edit.close()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/idlelib/", line 1017, in close
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/idlelib/", line 309, in _close
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/idlelib/", line 1021, in _close
AttributeError: 'NoneType' object has no attribute 'filename'
msg331023 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2018-12-04 10:00
Serhiy, this issue appears to be about an exception raised when an IDLE editor shutdown is called twice. Any thoughts would be appreciated. 

The recent #35263 and old #17822 are also intermittant unsolved None attribute errors.  #17614 (spunoff from *17613) fixed an instance of this exact error.  #22614 fixed a related error. 

For an editor, io is unconditionally set and unset in __init__ and _close with
 249: = io = self.IOBinding(self) # from
1026: = None
The reset to None is after the failing test, so it seems that failure is not possible.  There is no other occurrence of re 'io\s=\sNone' in idlelib.

There are, however, 3 explicit explicit tests of

1., 1005-6, David Scherer in 2009, no issue or commit message.
    def maybesave(self):
        if  # should add '== None' here and 'return None' at end.
Called by close() before _close().

2., Roger Serwy, #17614, 265-270
    def restore_file_breaks(self):  # part of editor initialization
        self.text.update()   # this enables setting "BREAK" tags to be visible
        if is None:
            # can happen if IDLE closes due to the .update() call
Triggered by editing a large file and hitting Alt-F4 after the editor window appears but before initialization is complete.  (Should add issue to comment.)

3., Serhiy Storchaka, 154-8
    def color_breakpoint_text(self, color=True):
        "Turn colorizing of breakpoint text on or off"
        if is None:
            # possible due to update in restore_file_breaks

The latter two are a race condition of close being called by an event handler while initialization is ongoing.  This does not obviously apply to maybesave or this issue, but maybe somehow close can be called again while still executing.

The failing line is followed by
If there is no io, this cannot execute, and the test might be changed to
         if in not None and
However, would then fail.  Even with that fixed, I imagine that other shutdown  calls in _close() could fail.  If 'self.per = None' or ' are called once, a subsequent self.per or will fail.
Date User Action Args
2018-12-11 21:09:46terry.reedysetnosy: + ronaldoussoren, ned.deily

components: + macOS
versions: + Python 3.8
2018-12-04 10:00:56terry.reedysetnosy: + serhiy.storchaka
messages: + msg331023
2018-12-02 18:30:10rhettingercreate