Re: tk.after troubles
Wed, 08 Jun 1994 11:06:05 +0200

> This is a small Tkinter program that creates an empty Tk window, then uses
> 'after' to call the function 'everytime' every 20 milliseconds.
> After about 30 seconds or so, I get this message:
> tkerror failed to handle background error.
> Original error: too many nested calls to Tcl_Eval (infinite loop?)
> Error in tkerror: too many nested calls to Tcl_Eval (infinite loop?)
> The Python process has also grown from about 1.5M to 5M. Commenting out the
> 'root1.mainloop()' in everytime results in the program exiting. Having
> widgets does *not* solve the problem - I'm guessing it is a bug with the
> after interface.
> -- cut here --
> from Tkinter import *
> root1 = Tk()
> tk1 =
> def everytime():
> root1.after(20, everytime)
> root1.mainloop()
> def main():
> root1.after(20, everytime)
> root1.mainloop()
> main()

It should work woth the mainloop() call taken out of everytime() -- if
you put it it, everytime() will never return and this indeed the stack
will grow indefinitely.

If I try it with the mainloop() call taken out of everytime(), I get a
more serious error, not just an exit:

>>> main()
called Tcl_CreateHashEntry on deleted tableIOT trap - core dumped

Looking in's definbition of after(), I find that it calls
createcommand for each call. Since it gets passed the same function
each time that may be the problem. Steen?

--Guido van Rossum, CWI, Amsterdam <>
URL: <>