多次遇到类似的代码结构,当我在 threading.Thread
实现中看到这一点时,我只需要问一下 self.master.after( 100, self.periodicCall)
消耗越来越多的内存,因为它是一个递归函数调用......是的,不是吗?
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
最佳答案
periodicCall
方法不直接调用自身;这不是递归调用。
它请求 tkinter 事件循环在给定时间内调用该方法;无需担心内存消耗。
关于python - .after() 方法递归,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27745184/