This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients JanKanis, pitrou, serhiy.storchaka, terry.reedy
Date 2014-05-28.18:44:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1401302645.05.0.115504960881.issue18141@psf.upfronthosting.co.za>
In-reply-to
Content
My worry about the patch is that is is a bandage covering up a problem elsewhere.

1. You indicate that you only have a problem with your custom build, but not on a standard build. This seems odd. Perhaps the problem is with your build.

2. turtledemo.__main__ only calls root.destroy indirectly via
        root.wm_protocol("WM_DELETE_WINDOW", self._destroy)
    def _destroy(self):
        self.root.destroy()
        sys.exit()
Let's assume that .destroy is called when the exception happens (verifiable by adding "print('destroy called')".)

3. The purpose of Tk.destroy is to cleanly deconstruct the gui before python's random cleanup. Should it have cleared PhotoImage?

Image and Variable (and subclasses) are the only classes in tkinter.__init__ with __del__ methods. Both have a tcl.call, so Variable potentially has the same problem as Image. But neither seem to have a problem in routine tkinter use.

4. Why is there a PhotoImage to be deleted? Idle Find in Files does not find 'PhotoImage' in turtledemo/*.py. I believe it is created as follows. turtledemo.DemoWindonw.__init__ contains this odd pair of lines that initializes a turtle.Screen instance with turtle.TurtleScreen.__init__ (TurtleScreen subclasses TurtleScreenBase, not Screen).
        self.screen = _s_ = turtle.Screen()
        turtle.TurtleScreen.__init__(_s_, _s_._canvas)
The latter call creates a collection of default turtles (_shapes) that includes 'blank', a 1x1 (pixel) blank PhotoImage that gets tkinter._default_root as (default) master.

I suspect that adding either of these lines to _destroy would prevent the TclError.
    del self.screen  # before self.root.destroy()
    import tkinter; tkinter._default_root.destroy()  # after self.root

5. While it seems like a buglet for turtle to create a hidden PhotoImage, with an anonymous master, and not clean it up somehow; and while I am puzzled if this never happens with standard builds; it seems plausible that we could patch Variable/Image.__delete__ to be sure they do not leak an exception.

Serhiy, what do you think?
History
Date User Action Args
2014-05-28 18:44:05terry.reedysetrecipients: + terry.reedy, pitrou, JanKanis, serhiy.storchaka
2014-05-28 18:44:05terry.reedysetmessageid: <1401302645.05.0.115504960881.issue18141@psf.upfronthosting.co.za>
2014-05-28 18:44:05terry.reedylinkissue18141 messages
2014-05-28 18:44:01terry.reedycreate