BlueberryCake Noobie
BlueberryCake Noobie

Reputation: 45

.after() method recursion

Came across similar code structure a number of times and when I saw this in a threading.Thread implementation, I just needed to ask wouldn't the line self.master.after(100, self.periodicCall) consume more and more memory as it is a recursive function call... It is, isn't it?

class arbitraryClass():
    def __init__(self, master):
        ... # other miscellaneous codes not shown here
        self.periodicCall() # within the __init__() method

    def periodicCall(self): 
        self.doSomething() #arbitrary method
        self.master.after(100, self.periodicCall)
        ... # other miscellaneous codes not shown here

Upvotes: 1

Views: 750

Answers (2)

Ron
Ron

Reputation: 1508

The method is not recursive.

The callback is only run once for each call to after(). To call it repeatedly, you need to reregister the callback inside itself.

Upvotes: 0

falsetru
falsetru

Reputation: 369134

periodicCall method does not call itself directly; it's not a recursive call.

It request tkinter event loop to call the method in given time; no need to worry about memory consumption.

Upvotes: 2

Related Questions