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 pysquared
Date 2006-07-24.09:29:52
SpamBayes Score
Marked as misclassified
Logged In: YES 

> The patch looks wrong. Why are you deleting the
> _tkcommands of the master widget if the variable
> is deleted? The master could live much longer,
> and the commands might still be needed.

AIUI, Tkinter callbacks (Button and Scrollbar commands, Text
[xy]view, event, protocol and variable bindings, after
callbacks etc) should always be given a Python callable, and
not the Tcl name of an already bound Python command.
 b1 = Button(root, command=pressed)
 b2 = Button(root, command=b1['command']) # Share command
 b2.invoke() # Callback is invalid, and rightly so
Given that, when a Variable is deleted, is needs to clean up
the Tcl commands it created, as no other widget has a
reference to them, and they are no longer needed, and there
will be no other way of deleting them.
By the time __del__() deletes any 'u' callbacks, they have
already been called, as globalunsetvar is called first, so
this is safe.

> What is the purpose of the changes to trace_variable?
> You are supposed to invoke trace_vdelete to release the
> callback.

Is it the aim for Tkinter to work in a similar way to
Python's reference counted and garbage collected mem-man?  I
assume it is, so the changes track commands associated with
the variable, for cleanup on collection.
See next comment below for explanation of TclError.

> Why are you catching TclError in so many cases? Under what
> circumstances can you even get an error?

The following all raise TclError:
w.after("spam", eggs) # bad argument "spam": must be cancel,
idle, info, or a number
w.bind("<spam>", eggs) # bad event type or keysym "spam"
w.bind_all("<spam>", eggs) # bad event type or keysym "spam"
w.bind_class("Button", "<spam>", eggs) # bad event type or
keysym "spam"
w.config(spam=eggs) # unknown option "-spam"
v.trace_variable("spam", eggs) # bad operations "spam":
should be one or more of rwu

When the exception is raised, the 'eggs' Tcl command for the
'spam' callback has already been created.  The exception
means the "command-id" is never returned for use in cleaning
up manually.  So, the patch cleans up on exception
automatically.  I don't think the argument that it's OK for
incorrect use to result in memory leaks holds any water :-)
 I may of course be missing the obvious.

> I think I would prefer if this patch was split into many
> individual ones, each one fixing only a single
> bug (assuming there are multiple bugs in Tkinter).

Sorry for the rushed patch, I noticed the release schedule
for Python2.5 and just put together the patch from
monkey-patch code I had already been using, tested it and
uploaded.  The program mentioned tests all the
fixes, but I did not have time to add them to the Python
test suite.
I realise you probably have many demands on your time
(fielding loads of patches like this one :-), like I do
(baby imminent! work demands etc.), so I hope the
explanations above help (I should have explained all this
before), if not I may be able to submit separate patches and
tests at a later date.

Many thanks, Graham Horler
Date User Action Args
2007-08-23 15:53:37adminlinkissue1524639 messages
2007-08-23 15:53:37admincreate