多次遇到类似的代码结构,当我在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发布于 2015-01-02 16:29:06
periodicCall方法不直接调用自己;它不是递归调用。
它请求tkinter事件循环在给定的时间内调用该方法;不需要担心内存消耗。
发布于 2016-10-17 07:08:53
该方法不是递归的。
对after()的每个调用只运行一次回调。要重复调用它,需要重新注册回调本身。
https://stackoverflow.com/questions/27745184
复制相似问题